Monday, October 6, 2014

Modify $PATH for all users in CentOS

Question
We just got our new server(s) up and we're running CentOS on them all. After successfully installing Ruby Enterprise Edition, I would now like to add the REE /bin (located at /usr/lib/ruby-enterprise/bin) directory to make it the default Ruby interpreter on the server.
I have tried the following, which only adds it to the current shell session:
export PATH=/usr/lib/ruby-enterprise/bin:$PATH
What would be the correct approach to permanently adding this directory to $PATH for all users. I am currently logged in as root.
Thanks in advance!


Answer

It's not a good idea to edit /etc/profile for things like this, because you'll lose all your changes whenever CentOS publishes an update for this file. This is exactly what /etc/profile.d is for:
# echo 'pathmunge /usr/lib/ruby-enterprise/bin' > /etc/profile.d/ree.sh
# chmod +x /etc/profile.d/ree.sh
Log back in and enjoy your (safely) updated PATH:
# echo $PATH
/usr/lib/ruby-enterprise/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
# which ruby
/usr/lib/ruby-enterprise/bin/ruby
Instead of logging back in, you could reload the profile:
# . /etc/profile
This will update the $PATH variable.

No comments:

Post a Comment