Set PATH Environment variable in Ubuntu

There is a multitude of information available through Environment variables. When a user logs in, there are few variables which are assigned by default. Other system utilities can make use of the available information stored in Environment variables. Besides, we can also make necessary modifications to these Environment variables as and when required. In this article, we would discuss how to set PATH Environment variable in Ubuntu distribution.

First, we can display values stored in Environment variables through either env or printenv command-line utilities. Therefore, issue the following in terminal –

env

or,

printenv

Since, we are discussing PATH environment variable. Hence, to print the values stored in PATH environment variable –

echo $PATH

The output may resemble –

/usr/local/sbin:/usr/local/bin:/usr/sbin

Now, before venturing ahead, the PATH Environment variable stores the location of our executables. For instance, if there is an executable present in directory – /usr/local/sbin then we can execute the file directly i.e. without providing its complete path.

In articles, we have discussed earlierInstall Blender in Ubuntu 19.10. We entered relevant PATH information in .bashrc file. And, this way we could open the executable directly. Thus, saving us valuable time.

Set PATH Environment variable in Ubuntu

We can either make temporary or permanent changes to Environment variables.

I. Make temporary changes to environment variables –

Open a terminal and use export command-line utility to add the PATH of our executable.

export PATH=$PATH:/path/to/executable

Now, verify whether changes have been made –

echo $PATH

Output may resemble –

/usr/local/sbin:/usr/local/bin:/usr/sbin:/path/to/executable

This will allow us to execute the file available in specified location directly. For instance, now we can run blender directly –

blender

instead of –

/path/to/executable/blender

But, all changes will be lost once we exit from the current terminal session.

II. Make Permanent changes to environment variables –

We need to edit ~/.bashrc file to make permanent modifications. Use a text editor like nano to open the file –

nano  ~/.bashrc

and, append the file with the following –

export PATH=$PATH:/path/to/executable

Now, to force changes in current terminal session –

. ~/.bashrc

or, open a new terminal session and issue the following to verify –

echo $PATH

Output may resemble –

/usr/local/sbin:/usr/local/bin:/usr/sbin:/path/to/executable

In conclusion, we have discussed how to set PATH Environment variable in Ubuntu distribution.

Similar Posts