Add a path in $PATH globally for every user

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Global paths should be set in /etc/profile or /etc/environment, just add this line to /etc/profile:

PATH=$PATH:/path/to/ANT/bin

Method 2

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

Method 3

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x