Environment Variables
Environment variables are dynamic values that influence the behavior of processes and applications on a computer. They configure system settings, manage paths to executable files and libraries, and store user-specific information such as home directories and shell preferences. By setting and modifying these variables, users and programs can customize the operating environment to suit specific needs, control application behavior, and streamline the execution of scripts and commands. Environment variables are typically defined in configuration files like .bashrc
or .bash_profile
and can be accessed or changed using commands in the terminal.
Initialize Your Environment
LCC and MCC use Bash as the default shell. When a session starts, it reads commands from the following files:
~/.bashrc
~/.bash_profile
Environment variables are set in ~/.bashrc
. You can also set aliases in ~/.bash_aliases
.
The files ~/.bash_profile
and ~/.bashrc
are hidden. To list hidden files, type ls -a
.
Know the Environment Variables
Here is a list of some common environment variables:
$HOME
- Path of your home directory$PATH
- List of directories where the system checks for programs to run$LD_LIBRARY_PATH
- List of directories where the system checks for shared libraries to load$HOSTNAME
- The name of the host machine
To see all your environment variables, type env
in your terminal.
[linkblue@login004 linkblue]$ env
MKLROOT=/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/mkl
LMOD_FAMILY_COMPILER_VERSION=19.1.3.304
MANPATH=/opt/ohpc/pub/intel/compilers_and_libraries_2019.4.243/linux/mpi/man:/usr/local/share/man:/usr/share/man:/opt/ohpc/pub/intel/man/common:/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/mpi/man:/opt/ohpc/pub/intel/documentation_2020/en/debugger/gdb-ia/man::/opt/ohpc/pub/utils/autotools/share/man:/usr/share/man/overrides:/usr/share/man/en
XDG_SESSION_ID=403260
_ModuleTable003_=bGVkZXBzL2ludGVsL2ltcGkvMjAxOS40LjI0MyIsWyJmdWxsTmFtZSJdPSJpbXBpLzIwMTkuNC4yNDMiLFsibG9hZE9yZGVyIl09NCxwcm9wVD17fSxbInN0YWNrRGVwdGgiXT0xLFsic3RhdHVzIl09ImFjdGl2ZSIsWyJ1c2VyTmFtZSJdPSJpbXBpIix9LGludGVsPXtbImZuIl09Ii9vcHQvb2hwYy9wdWIvbW9kdWxlZmlsZXMvaW50ZWwvMTkuMS4zLjMwNCIsWyJmdWxsTmFtZSJdPSJpbnRlbC8xOS4xLjMuMzA0IixbImxvYWRPcmRlciJdPTMscHJvcFQ9e30sWyJzdGFja0RlcHRoIl09MSxbInN0YXR1cyJdPSJhY3RpdmUiLFsidXNlck5hbWUiXT0iaW50ZWwiLH0sb2hwYz17WyJmbiJdPSIvb3B0L29ocGMvcHViL21vZHVsZWZpbGVzL29ocGMiLFsiZnVsbE5hbWUiXT0ib2hw
HOSTNAME=login004
__LMOD_REF_COUNT_CLASSPATH=/opt/ohpc/pub/intel/compilers_and_libraries_2019.4.243/linux/mpi/intel64/lib/mpi.jar:1;/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/mpi/intel64/lib/mpi.jar:1;/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/daal/lib/daal.jar:1
IPPROOT=/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/ipp
__LMOD_REF_COUNT_MODULEPATH=/opt/ohpc/pub/moduledeps/intel-impi:1;/opt/ohpc/pub/moduledeps/intel:1;/opt/ohpc/pub/modulefiles:1
TERM=xterm
SHELL=/bin/bash
PROJECT=/project
HISTSIZE=1000
SSH_CLIENT=10.163.62.38 50931 22
LIBRARY_PATH=/opt/ohpc/pub/intel/compilers_and_libraries_2019.4.243/linux/mpi/intel64/libfabric/lib:/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/mpi/intel64/libfabric/lib:/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/ipp/lib/intel64:/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/compiler/lib/intel64_lin:/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/mkl/lib/intel64_lin:/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/tbb/lib/intel64/gcc4.8:/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/daal/lib/intel64_lin:/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/daal/../tbb/lib/intel64_lin/gcc4.4:/opt/ohpc/pub/intel/compilers_and_libraries_2020.4.304/linux/daal/../tbb/lib/intel64_lin/gcc4.8
LMOD_PACKAGE_PATH=/opt/ohpc/pub/lmod-local-packages
LMOD_PKG=/opt/ohpc/admin/lmod/lmod
LMOD_VERSION=8.0.6
...
Set and Modify Environment Variables
Display the value of an environment variable using echo
:
[linkblue@login004 linkblue]$ echo $HOME
/home/linkblue
Set or modify the value of environment variables with export
:
[linkblue@login004 linkblue]$ export PATH=$PATH:/home/$USER
Center for Computational Sciences