Atlantic.Net Blog

How to Set Environment Variables in Linux

A variable is a location for storing a value which could be a filename, text, number or any other data.

A variable is usually referred to with its symbolic name. The value stored can be displayed, deleted, edited, and re-saved. Variables play an important role in computer programming because they enable programmers to write flexible programs.

An environment variable alters the dynamic values which affect the processes or programs on a computer. They exist in every operating system and their types vary. Environment variables also give information about system behavior and can change the behavior of software and programs.

In this tutorial, we will show you how to set environment variables in Linux.


  • A fresh Ubuntu 20.04 VPS on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server.  Create a new server, choosing Ubuntu 20.04 as the operating system, with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – List Environment Variables

You can list all environment variables in your system by running the following command:




You should see the following screen:

There are a lot of environment variables available in Linux, including HOME, USER, EDITOR, PATH, LANG, TERM, MAIL, SHELL, and many more.

You can display the value of specific variable by passing the name of the variable to the printenv command.

For example, to display the value of the LANG variable, use the following command:

printenv LANG

You should see the following output:


Step 3 – Set up an Environment Variable

There are two types of variables: Shell variables and the Environment variables.

To create a new shell variable named COMPANY with value Atlantic, use the following command:


Next, you can verify the variable using the echo command:


You should see the value of your variable in the following output:


You can also verify whether the above variable is an environment variable or not using the printenv command:

printenv COMPANY

You should see the empty output which means the variable is not an environment variable.

To create a new environment variable named ORGANIZATION, use the export command:

export ORGANIZATION=Atlantic

You can verify the environment variable with the following command:


You should get the following output:


The environment variables which you have created in this way are available only in the current session. If you log out of your system, all variables will be lost.

You can also unset an environment variable you created earlier using the unset command followed by the variable name.

For example, to unset an ORGANIZATION variable, use the following command:


Step 4 – Set up Persisting Environment Variable

When you set an environment variable using the export command, its existence ends when the user’s session ends, so it is recommended to set environment variables that are persist across sessions.

To set persisting environment variables globally, you will need to define them in /etc/profile file.

For example, you can set the persisting environment variable named COMPANY with value Atlantic by editing /etc/profile file as shown below:

nano /etc/profile

Add the following line at the end of the file:

export COMPANY=Atlantic

Save and close the file when you are finished, then activate the variable with the following command:

source /etc/profile

You can also set a persisting environment for a specific user by editing the user’s .bashrc file.

For example, set a persisting environment named VAR with value “My Linux Box” by editing the user’s .bashrc file:

nano ~/.bashrc

Add the following line at the end of the file:

export VAR="My Linux Box"

Save and close the file when you are finished, then activate the environment variable with the following command:

source ~/.bashrc


In the above guide, you learned how to set and unset an environment variable in Linux. Environment variables are very useful for developers who will need to read or alter the environment of your system. If you’re ready to try setting an environment variable in Linux, get started on dedicated server hosting from Atlantic.Net.

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year