- How to set PATH environment variable?
- How to set JAVA_HOME environment variable?
- How to set Java bin directory to PATH?
- How to set JBOSS_HOME environment variable? (If you are using JBoss Appliation Server)
- How to set ANT_HOME environment variable and its bin to PATH? (If you are using Ant build tool)
If you want to set these variable globally. Then you need to make entry for these variables in the file
Otherwise, for a specific user: In your home directory* of Linux you have a file
".bash_profile". So you need to modify this file. As this is a hidden file, so you will not find this by typing ls command. To see it use -ls option. E.g.
[email@example.com,12.1 ~] ls -la
Now to modify this file use the vim Editor (You should know how to use the vi editor in Linux.). E.g.
[firstname.lastname@example.org,12.1 ~] vi .bash_profile
[email@example.com,12.1 ~] vi /etc/profile
Now suppose you have
Java Home directory:
Java bin directory:
Ant Home directory:
Ant bin directory:
JBoss Home directory:
So the sample
.bash_profile file is:
if [ -f ~/.bashrc ]; then
Similarly you can do for
/etc/profile(if you are willing to set these variable globally).
Now this is all done. Now logout and login again. Now verify all the environment variables using
echo command. e.g.
[firstname.lastname@example.org,12.1 ~] echo $PATH
[email@example.com,12.1 ~] echo $JAVA_HOME
[firstname.lastname@example.org,12.1 ~] echo $ANT_HOME
[email@example.com,12.1 ~] echo $JBOSS_HOME
** Home Directory: When you first login to any Linux system, by default you are in you home directory first, e.g. if you login with user name suppose “ranjan”, your home directory is:
/home/ranjan. Your home directory can always check by the
$HOME environment variable. So to check it, you can use the echo command in the following way:
[firstname.lastname@example.org,12.1 ~] echo $HOME
Some flavour of Linux may not have
.bash_profile file. It may have file like
.profile or something else. Modifying
/etc/profile instead of
.bash_profile has an advantage. In this case you do not need to install Java separately for each user. There is a single installation of java in
/usr/java/ directory, and single entry for the environment variables in
/etc/profile for all the users.