add bin path to $PATH
来源:互联网 发布:淘宝页面背景图 编辑:程序博客网 时间:2024/05/19 13:44
The shell path for a user in macOS or OSX is a set of locations in the filing system whereby the user has permissions to use certain applications, commands and programs without the need to specify the full path to that command or program in the Terminal. This will work in macOS Sierra and all older OSX operating systems; El Capitan
So instead of running something like this, with a path to the command:
/usr/local/mysql/bin/mysql
You can just type the command, regardless of where you are in the filing system:
mysql
Your shell path is a bunch of absolute paths of the filing system separated by colons :
You can find out whats in your path by launching Terminal in Applications/Utilities and entering:
echo $PATH
And the result should be like this…
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
So this is stating that you can run Unix style applications located in 5 default locations of path in the filing system:
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/bin
These directories are not visible by default in the filing system but you can make them visible.
Adding a Temporary Location
You can add extra locations to your path, in the mysql example above it’s location /usr/local/mysql/bin which is not in the default path, you can add it in Terminal like so:
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin
So here I have copied my existing path and added the new location on the end. Test it is added by runningecho $PATH again. One of the disadvantages of this is that the new location will only be honored for that particular Terminal session, when a new Terminal window is launched it will have the original default pathagain.
Adding in a Permanent Location
To make the new path stick permanently you need to create a .bash_profile file in your home directory and set the path there. This file control various Terminal environment preferences including the path.
cd
Move into home directory
nano .bash_profile
Create the .bash_profile file with a command line editor called nano
export PATH="/usr/local/mysql/bin:$PATH"
Add in the above line which declares the new location /usr/local/mysql/bin as well as the original pathdeclared as $PATH.
Save the file in nano by clicking ‘control’ +’o’ and confirming the name of the file is .bash_profile by hitting return. And the ‘control’+’x’ to exit nano
So now when the Terminal is relaunched or a new window made and you check the the path by
echo $PATH
You will get the new path at the front followed by the default path locations, all the time
/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Rearranging the default $PATH
If you needed to rearrange the paths in the default $PATH variable, you can just do that and leave off $PATH.
So lets say you want /use/local/bin at the beginning to take precedence you can add the default path like so inside .bash_profile
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
And then you can slot in other paths as required.
- add bin path to $PATH
- IDL add subdirectories to PATH
- How to add a path to matlab search path permanently
- LeetCode 112. Path Sum Add to List
- LeetCode-Add to List 71. Simplify Path
- binary tree path add
- build path - Add Library
- linux add $PATH
- add path command
- add a new path to visit in matlab
- leetcode124~Binary Tree Maximum Path Sum Add to List
- leetcode 113. Path Sum II Add to List
- [leetcode] 64. Minimum Path Sum Add to List
- eclipse中Build Path-Add to Build Path对应到androidstudio的设置
- eclipse中Build Path-Add to Build Path对应到androidstudio的设置
- 安装 VMWare tools 时出现“The path "/usr/bin/gcc" is not valid path to the gcc binary”解决
- /etc/profile add PATH variable
- path
- delphi运算符集合
- Axure学习——我的第一个原型设计
- 大学,一路走好
- PHP.1-网站开发概述
- 大神的ACM训练计划(详细)
- add bin path to $PATH
- 你好,第二月!
- Volley的使用
- HDU2089 不要62(数位dp)
- HDU2489【状压枚举】
- Xcode7.2/真机iOS10报错:could not find developer disk image
- 报错:1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost
- ACM训练表
- [XSS]收集几个在线JS加密地址