set PATH permanently

5

How do I edit my .profile file to set a permanent value for my PATH variable?

Is there any other file that needs editing? (This is on CentOs 6.2)

user1508893

Posted 2013-01-23T22:11:42.377

Reputation:

1Why did you close my question???? What's wrong with asking stuff that one doesn't knwo? – None – 2013-01-23T22:18:18.830

Stack Overflow is for questions about programming. You may have better luck with this question at http://unix.stackexchange.com/.

– KatieK – 2013-01-24T01:31:01.183

Answers

5

You'll probably want to do this in your shell's rcfile (.bashrc, .zshrc, etc.). You'll want to add something like the following:

export PATH=$PATH:/new/folder/path

if you are only looking to append a file path. Or you can get tricky with it and create a path file (for zsh I have a .zpath file). In there you can do something like:

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
export PATH

Now every time that file is sourced (source ~/.zpath for example) it will load those paths into your environment. You can add source ~/.zpath to your rcfile so this will happen every time you log in or create a new shell.

mgoffin

Posted 2013-01-23T22:11:42.377

Reputation: 161

I don't want to append new values to PATH. I want to remove some values, and replace some others with new stuff. Should I just put export PATH= <new path> in my .bashrc file? (I put this in my .profile file, but it didn't seem to ahve any effect) – One Two Three – 2013-01-24T20:18:23.790

Yea, put that in your .bashrc. – mgoffin – 2013-01-24T20:39:17.383

Thanks! (I don't know how to mark your answer as the answer, though). (THere is supposed to be a check symbol, isn't there?) – One Two Three – 2013-01-24T20:41:18.510

Not entirely sure (I haven't asked any questions yet). I thought there was a check image under the upvote/downvote. – mgoffin – 2013-01-24T21:11:21.280

1

 - Go to /etc/profile 
Go to line # Path manipulation if [ "$EUID" = "0]; then
       pathmunge /sbin
       pathmunge /usr/sbin
       pathmunge /usr/local/sbin

   ***add your path like this- pathmunge /your/path

** or you change userid (0 is root) or add more conditions like

   if [ "$EUID" >= "0" ]; then
       pathmunge /sbin
       pathmunge /usr/sbin
       pathmunge /usr/local/sbin 
   ** to find your id type this command at prompt #id

And reboot the system

sukesh

Posted 2013-01-23T22:11:42.377

Reputation: 11

0

I think make a bashscript for this you need to use the profile.d /etc/profile could be replaced by an update?

vi /etc/profile.d/path.sh

!/bin/bash

export PATH=$PATH:/new/folder/path:/opt/anotherpath:/etc/etc/etc

save it and chmod +x /etc/profile.d/path.sh

Marcel Kraan

Posted 2013-01-23T22:11:42.377

Reputation: 1

Please read the question again carefully. Your answer does not answer the original question, which ask about "set PATH permanently" – DavidPostill – 2016-08-27T07:44:48.900