How to Configure Environment Variables in Linux (CentOS)

Recently I was working on Hadoop and to run Hadoop it requires Java 6 JDK to be configured in my Linux CentOS distribution. I’m going to share how to configure Environment variables for user and system.

If you are experienced Windows user you might know what is environment variables. Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. (from Wikipedia)

There are two types of environment variables

1. User environment variables – settings and path applies to a particular user

2. System environment variables – settings and path applies to all the users in the OS.

Let me take for instance if you want to configure Java path in the Linux machine. First, download and install the particular Java JDK (Java 6 JDK) package and after installing you should find java folders (/usr/java/jdk1.6.0_22/) that to be added for path variable.

User environment variable

Open your terminal and type

# vi ~/.bash_profile

Now add the path in bash_profile file and reboot your machine once

export PATH=$PATH:/usr/java/jdk1.6.0_22/bin

After rebooting open the terminal and type $PATH where you can find the added Java path in the output

System environment variable

The system environment variable is a global configuration where it applies to all users.

Open /etc/profile file and add the path for your application.

For instance

# vi /etc/profile

Adding path entry in the profile file

export PATH=$PATH:/usr/java/jdk1.6.0_22/bin

Reboot your machine once and type $PATH in the terminal, you can see the path now which is available for all the users.