Adding a directory to $PATH in CentOS?

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.

Leave a Comment