PATH=/data/myscripts:$PATHTo add that directory to the end of the path, use the following command:
PATH=$PATH:/data/myscripts 重启Terminal后生效;若希望设置路径立即生效,可输入:
source .bashrc
Adding to a Single User's Path
To add a directory to the path of a single user, place the lines in that user's .bash_profile file. Typically, .bash_profile already contains changes to the $PATH variable and also contains an export statement, so you can simply add the desired directory to the end or beginning of the existing statement that changes the $PATH variable. However, if .bash_profile doesn't contain the path changing code, simply add the following two lines to the end of the .bash_profile file:PATH=$PATH:/data/myscripts export PATH
Adding to All Users' Paths (except root)
You globally set a path in /etc/profile. That setting is global for all users except user root. Typical /etc/profile files extensively modify the $PATH variable, and then export that variable. What that means is you can modify the path by appending or prepending the desired directory(s) in existing statements modifying the path. Or, you can add your own path modification statements anywhere before the existing export statement. In the very unlikely event that there are no path modification or export statements in /etc/profile, you can insert the following 2 lines of code at the bottom of /etc/profile:
PATH=$PATH:/data/myscripts export PATH
Adding to the Path of User root
User root is a special case, at least on Mandrake systems. Unlike other users, root is not affected by the path settings in /etc/profile. The reason is simple enough. User root's path is set from scratch by its .bash_profile script. In order to add to the path of user root, modify its .bash_profile.Summary
A fundimental administration task is adding directories to the execution paths of one or more users. The basic code to do so is:PATH=$PATH:/data/myscripts export PATH
Place that code, or whatever part of that code isn't already incorporated, in one of the following places:
User Class | Script to modify |
One user | $HOME/.bash_profile |
All users except root | /etc/profile |
root | /root/.bash_profile |
Quoted from: http://www.troubleshooters.com/linux/prepostpath.htm
Linux设置环境变量,方法很多,下面是其中一种方法:
回复删除1. 编辑.bashrc
vim ~/.bashrc
添加:
PATH=$PATH:XXXXXX
export PATH
2. 执行
source ~/.bashrc