Skip navigation

Tag Archives: Setting path in Linux

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
export PATH

Other alternative is create .sh in folder /etc/profile.d/, for example 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, enter path setting like in above sample. Save and reboot your computer.

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