Skip navigation

There is few ways to set path or environment variables in linux. Not every linux distros had the same way to do this, but the commons way we can set path using this three methods:

– using file ~/.bashrc
– using file ~/.bash_profile
– create bash file (*.sh) in folder /etc/profile.d/

Sometimes in a linux distro can use all that three methods, sometimes it isn’t, based on the distro. We only have to use one of that three methods to setting path or environment variables.

I don’t really know what is the different between setting path in ~/.bashrc or in ~/.bash_profile, the result is the same🙂 . It’s user level bash file, the setting is only work for current user. I think when a user login or a user open a shell terminal, it will read settings on those two files (user own version). To set path in that two files just open in text editor or using VI editor, and enter the path, usually in the last line. Save and reopen shell terminal. The sample will look like:

export JAVA_HOME=/opt/jdk1.6.0
PATH=$PATH:$JAVA_HOME/bin:.
export PATH

Other alternative is create .sh in folder /etc/profile.d/, for example blablabla.sh. To create file in that folder we need root access, and the setting will apply in all user, so it’s system wide setting (that’s i called it). Again i think when linux boot and run, it will read every *.sh files in the folder and set the linux system based on the files. But notes, not every linux distro set linux system using this method, sometimes it’s not working. So in the blablabla.sh, enter path setting like in above sample. Save and reboot your computer.

If there’s other ways, please tell me. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: