Skip to main content

Command Palette

Search for a command to run...

Linux Environment Variables

Published
2 min read
Linux Environment Variables

Environment Variables:

Environment variables are a set of dynamic named values that can affect the way running processes will behave on the system. These variables are used by the operating system and applications to store important information that can be accessed by various programs or scripts.

Some environment variables in Linux are below:

  1. PATH: This variable stores the location of the directories containing the executable files that are used by the shell. The PATH variable is used to search for a command when it is entered into the shell.

  2. HOME: This variable stores the path of the user's home directory.

  3. USER: This variable stores the name of the current logged-in user.

  4. SHELL: This variable stores the path of the current shell that is being used by the user.

  5. TERM: This variable stores the type of terminal or console that is currently being used by the user.

  6. LANG: This variable stores the current system language.

  7. DISPLAY: This variable stores the address of the X display server that is being used.

  8. PS1: This variable stores the primary prompt string that is displayed on the command line.

How to View Environment Variables?

  1. To View all the environment variables #printenv or env

  2. To View Only one environment variable #echo $<name_of_variable>.

How to SET Environment variables?

  1. To set the environment variable temporary.

#export DEVWAR=2

Access this DEVWAR Variable

To Set the environment variable permanently.

  1. #vi .bashrc

  1. ending of .bashrc file add below variable:

export DEVWAR=bhau

  1. After that reload .bashrc file using the below command and check variable:

To Set the global environment variable permanently.

  1. #vi /etc/profile

2. ending of /etc/profile file add below variable:

export DEVWAR=Dhiraj

  1. After that reload /etc/profile file using the below command and check the variable:

How to UNSET Environment Variables?

#unset <variable_name>

More from this blog

DevOps Blogs

44 posts