Setting Environmental Variable Path
- Lets try to install software terraform which is used by user ironman
- Lets try to install software packer which is used by user thor
- Lets try to install software java 8 which should be used by both the user
- After downloading terraform, unable to run command
- So lets add the folder of terraform to the path using export command
- Now i will logout of ironman, login & recheck & this fails
- So let create a file
echo 'export PATH=$PATH:/home/ironman/bin' > ~/.bash_profile
- Now logout & relogin & execute
printenv PATH
terraform --version
- Now lets do the samething for packer for thor
echo 'export PATH=$PATH:/home/thor/bin' > ~/.bash_profile
exit
# relogin
packer --version
sudo apt-get install openjdk-8-jdk -y
- Java can be used by all the users as java executable is added to folder which is in path for all the linux users.
- Now lets assume on the same machine ironman wants java 11 & all other users want java 8
sudo apt-get install openjdk-11-jdk -y
- All the users got JAVA 11, now how to solve this problem. If use ENVIRONMENTAL variable called as JAVA_HOME, the problem can be solved
- Add the following lines to /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH
- Add the following lines to /home/ironman/.bash_profile
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH