Unix set environment variable permanently

sysadmin
shell
bash

#1

How do I permanently set environmental variables running on Unix system? I want something like:

JAVA_HOME=/opt/IBM/WebSphere/AppServer/java_1.7.1_64
ORACLE_HOME=/home/oracle/app/oracle/product/11.3.0/client_200
PATH=$JAVA_HOME/bin:$PATH 

When I logout my settings deleted :frowning: How do I set a user environment variable and system environment permanently on Unix?


#2

add then to your .bashrc or .bash_profile - its get ‘run’ every time you log in.


#3

For bash shell edit ~/.bash_profile or ~/.profile file and add the following:

export JAVA_HOME=/opt/IBM/WebSphere/AppServer/java_1.7.1_64
export ORACLE_HOME=/home/oracle/app/oracle/product/11.3.0/client_200
export PATH=$JAVA_HOME/bin:$PATH 

For zsh shell edit ~/.zprofile and append the following:

export JAVA_HOME=/opt/IBM/WebSphere/AppServer/java_1.7.1_64
export ORACLE_HOME=/home/oracle/app/oracle/product/11.3.0/client_200
export PATH=$JAVA_HOME/bin:$PATH 

For ksh or sh (bourne) shell edit ~/.profile and append the following:

export JAVA_HOME=/opt/IBM/WebSphere/AppServer/java_1.7.1_64
export ORACLE_HOME=/home/oracle/app/oracle/product/11.3.0/client_200
export PATH=$JAVA_HOME/bin:$PATH 

For csh or tcsh shell edit ~/.login and append the following:

setenv JAVA_HOME /opt/IBM/WebSphere/AppServer/java_1.7.1_64
setenv ORACLE_HOME /home/oracle/app/oracle/product/11.3.0/client_200
setenv PATH $JAVA_HOME/bin\:$PATH 

For info see:

  1. TCSH / CSH Shell Set PATH Variable
  2. UNIX / Linux: Set your PATH Variable Using set or export Command
  3. How to add to bash $PATH permanently on Linux