Thanks to visit codestin.com
Credit goes to github.com

Skip to content

创建软链接 #134

@qingquan-li

Description

@qingquan-li

一、软链接是什么

Symbolic Link :符号链接(软链接),亦即是快捷方式。

How can I create a symbolic link in Terminal?

Symbolic Links.txt

OSX / Linux
===========
┌── ln(1) link, ln -- make links
│   ┌── Create a symbolic link.
│   │                         ┌── the path to the intended symlink
│   │                         │   can use . or ~ or other relative paths
│   │                   ┌─────┴────────┐
ln -s /path/to/original /path/to/symlink
      └───────┬───────┘
              └── the path to the original file/folder
                  can use . or ~ or other relative paths


Windows is OPPOSITE!
==============================
┌── mklink -- make link
│       ┌── Create a symbolic link. /H for hard file, /J for hard directory
│       │                          ┌── the path to the original file/folder
│       │                    ┌─────┴────────┐
mklink /D D:\path\to\symlink D:\path\to\original
          └───────┬───────┘
                  └── the path to the intended symlink

二、实例:macOS安装Python后创建软链接

macOS / Linux 用 ln -s 命令创建符号链接(软链接),类似于 Windows 创建桌面快捷方式,符号链接(软链接)存放在 /usr/local/bin 目录中。

$ ln -s 软件实际安装路径 /usr/local/bin  # 创建指向/usr/local/bin的软链接

注意:在 macOS 中 usr 是隐藏文件,使用快捷键 command+shift+. 以显示。


Python安装来源 Python安装路径
系统默认 /System/Library/Frameworks/Python.framework/Versions/2.7
官网pkg安装 /Library/Frameworks/Python.framework/Versions/3.5
brew安装 /usr/local/Cellar/python

为安装好的Python创建软链接

如果使用 $ brew install python 安装了最新版 python(3.6.3 )后,直接在终端输入 $ python3.6 或者 $ python3.6.3 将报错,因为并没有创建软链接放进 /usr/local/bin 目录中;

当然,终端中输入 $ /usr/local/Cellar/python3/3.6.3/bin/python3 也可以使用 python3.6.3 ,但是比较麻烦。

为新安装的 python3.6.3 创建指向 /usr/local/bin 的软链接,以后在终端输入 $ python3.6.3 实际上执行的就是 $ /usr/local/Cellar/python3/3.6.3/bin/python3

$ ln -s /usr/local/Cellar/python3/3.6.3/bin/python3 /usr/local/bin

注意:如果使用 $ brew install python #59 方式安装 Python ,可以直接使用命令 $ brew link python 。因为新版本 Homebrew 会自动在 /usr/local/bin 目录下生成名为 python3 的链接。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions