Do we have anyway to add a path globally so that each user gets it in $PATH. I want to add path of ANT so that each user doesn't need to add it in his $PATH variable.
Asked
Active
Viewed 1.2e+01k times
3 Answers
42
Global paths should be set in /etc/profile or /etc/environment, just add this line to /etc/profile:
PATH="$PATH:/path/to/ANT/bin"
terdon
- 234,489
- 66
- 447
- 667
-
2For ksh shell it was not working..after switching to bash shell it is working. Above changes are specific to bash shell ? – feel good and programming Jan 22 '21 at 13:24
-
@feelgoodandprogramming no, it should also work for `ksh`, but only if `ksh` is your login shell. The `/etc/profile` file is only read by login shells, so if you log in with `ksh`, then it will be read and any variables set there will be inherited by any other shells you launch. The details can get quite complicated though, I suggest you open a new question, tell us what operating system you use, how you log in, what your `$SHELL` is and other details and then we can examine why it didn't work for you. – terdon Jan 22 '21 at 13:42
25
Many Linux distributions support the Linux Standard Base /etc/profile.d directory where configurations such as additional paths directives can go without touching the stock system files. The file name just needs an .sh extension.
For example
cat >> /etc/profile.d/some_name.sh << \EOF
PATH=$PATH:/path/to/ANT/bin
EOF
NoelProf
- 678
- 7
- 6
-1
Edit /etc/profile and update the Path manipulation section. Centos does not include the /usr/local/bin in the path.
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
pathmunge /usr/local/bin
else
pathmunge /usr/local/bin after
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
fi
cwill
- 1
-
2It looks like your code assumes `bash` is being used. Also, notice the [tag:aix] tag on the question. This user is not using CentOS. – Kusalananda Mar 20 '19 at 18:06