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'm currently logged in as root
.
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:Log back in and enjoy your (safely) updated
$PATH
:Instead of logging back in, you could reload the profile:
This will update the
$PATH
variable.After following fmonk's advice I checked out
/etc/bashrc
, where I noticed it said that "Environment stuff goes in /etc/profile." I proceeded to look in/etc/profile
, I saw this:To solve my problem, I simply added
pathmunge /usr/lib/ruby-enterprise/bin
underneath the if statement. This solved my issue.SORRY misinterpretted the question the following asnwer is for a USER's profile leaving it in case it helps someone
modify .bash_profile
then somewhere in the file add/modify your paths seperated by :
then reload your profile
or logout and login again
if you check PATH it should include your newly added paths
Therefore I would not put environment variables in bashrc, because it is not only against common convention, but you will also miss your bashrc varialbles when invoking a terminal from a graphical Desktop environment.
On Redhat in the
/etc/profile
I found this comment:So if you want to set environment variables on a user basis, do it in the user's .bash_profile file.
Heading over to the
.bash_profile
I read:Conclusion
If you want only root to see programs residing, for instance in /
sbin
I would add that path to root's.bash_profile
file. But if you want every user to see what root specific programs are installed on your box I would put/sbin
into/etc/.profile
. Now every user can use tab completion to look for root specific programs and elevate rights if necessary.Special Case: SSH
When ssh is started with a commandline, an interactive login shell is started. But in this case
/etc/profile
is not read. When I defined environment variables in the.bash_profile
file of each user it worked with ssh.You can set environment variables in a .rc file; for bash shells (I believe the most common, and default in CentOS) each user has a file called .bashrc in his home directory.
Add the command PATH=/usr/lib/ruby-enterprise/bin:$PATH to this file to set it for any one particular user.
To set it for all users (as you mention), change it in /etc/bashrc (the default .bashrc in each user's home directory should source this file, but you should doublecheck that).
Why does everyone forget about
/etc/environment
. Setting environment variables for all users is what this file is for. Just add the name value pair of the environmental variable on one line. Don't use variables./etc/environment
This will add the directories
/usr/lib/ruby-enterprise/bin
/usr/bin
and/usr/local/bin
to your PATH variable, for all users, once you logout or restart./usr/bin
and/usr/local/bin
were already on my path before, but were removed for some reason after I edited this file. So add these two directories to be safe.