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)

3 Answers3

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
  • 161
2
 - 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
  • 21
1

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