How to permanently set $PATH on Linux/Unix?

2018-12-31 04:26发布

I'm trying to add a directory to my path so it will always be in my Linux path. I've tried:

export PATH=$PATH:/path/to/dir

This works, however each time I exit the terminal and start a new terminal instance, this path is lost, and I need to run the export command again.

How can I do it so this will be set permanently?

21条回答
ら面具成の殇う
2楼-- · 2018-12-31 05:05

It can be directly added by using the following command:

echo 'export PATH=$PATH:/new/directory' >> ~/.zshrc source ~/.zshrc

查看更多
弹指情弦暗扣
3楼-- · 2018-12-31 05:06

You can use on Centos or RHEL for local user:

echo $"export PATH=\$PATH:$(pwd)" >> ~/.bash_profile

This add the current directory(or you can use other directory) to the PATH, this make it permanent but take effect at the next user logon.

If you don't want do a re-logon, then can use:

source ~/.bash_profile

That reload the # User specific environment and startup programs this comment is present in .bash_profile

查看更多
永恒的永恒
4楼-- · 2018-12-31 05:10

one way to add permanent path, which worked for me, is: cd /etc/profile.d touch custom.sh vi custom.sh export PATH=$PATH:/path according to your setting/ restart your computer and here we go path will there permanently cheers.

查看更多
登录 后发表回答