Linux系统修改用户环境变量
用户环境变量通常被存储在下面的文件中:
- ~/.profile
- ~/.bash_profile
或者 ~./bash_login - ~/.bashrc
上述文件在Ubuntu 10.0以前版本不推荐使用。
系统环境变量
系统环境变量一般保存在下面的文件中:
- /etc/environment
- /etc/profile
- /etc/bash.bashrc
/etc/profile和
加入环境变量
如想将一个路径加入到$PATH中,可以像下面这样做(修改/etc/profile):
|
1
|
$sudo nano /etc/profile |
在里面加入:
|
1
|
export PATH="$PATH:/my_new_path" |
你可以自己加上指定的多个路径,中间用冒号隔开。环境变量更改后,在用户下次登陆时生效,如果想立刻生效,则可执行下面的语句:
|
1
|
$source /etc/profile |
需要注意的是,最好不要把当前路径”./”放到PATH里,这样可能会受到意想不到的攻击。
其他文件的修改方式与此类似,需要注意的是/etc/environment不需要使用export设置环境变量,其他profile文件需要。
文章的脚注信息由WordPress的wp-posturl插件自动生成
微信扫一扫,打赏作者吧~![[已解决]nc命令报错 close: Bad file descriptor](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2022/03/Snipaste_2022-03-18_20-16-48.png&w=280&h=210&zc=1)
![[已解决]SecureCRT/SSH 连接Linux缓慢](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/07/ssh_slow.jpg&w=280&h=210&zc=1)
![[转载]Linux的tickless设置](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.litrin.net/wp-content/uploads/2018/11/kernel_menuconfig_tickless-1.png&w=280&h=210&zc=1)
![[整理]鲲鹏性能优化十板斧(五)——应用程序性能调优<TaiShan特战队出品>](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/03/1-4.jpg&w=280&h=210&zc=1)