How to Show PATH of Environment Variable on Linux

Printing the PATH of environment variables on Linux isn’t a daunting task, provided you know how to proceed. In the following write-up, I’ll help you learn how to use some commands and show PATH of environment variables in seconds.

Typing Environment Variables

The process of printing all the environment variables is pretty straightforward. All you need to do is launch the Terminal using the “Ctrl+Alt+T” key combination and then invoke the following command:

$ env
show path environment variables

The output will look something like this:

You should also know that when the env command is used without an argument, your system will simply print the list of the current environment variables.

Instead of using the env command, you can also invoke printenv for this purpose. It will print every environment variable within the system, even those including the key:value pairs.

Input:

$ printenv

Output:

using printenv command

As you can understand from the output, the very first thing you’ll notice is the key:value pair. In case you don’t already know, among all the listed environment variables, the one that demands more specific attention is something called the PATH environment variable.

What is PATH?

When we talk about PATH, we’re looking at an environment variable that is specifically meant to allow the concerned system the capability of finding all sorts of executables. The process usually concludes simply by pointing the entities toward the appropriate directory. 

Speaking of Ubuntu-based systems, in particular, the PATH environment variable looks something like this:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
show path environment variables

It is crucial that you understand that the PATH here is nothing but the key, and the entity sitting right next to it is the value of the PATH variable. The usage of the colon (:) here actually helps separate each PATH. It ensures that a large number of directories can be seamlessly separated.

path

Understanding Environment Variables and Shell Variables

The best way to understand variables is by learning about both the environment and shell variables in detail. The environment variable reflects the variables that are usually available all throughout the system. These are generally inherited by every sired child process and the shells together.

On the other hand, Shell variables refer to the set that comes to play only to the currently concerned shell instance. No matter if we consider the shells like zsh or bash, both are home to a unique set of internal shell variables.

Variables: Syntax

Variables do bag a particular format. Here is what it looks like:

KEY=value
KEY= "Some other value."
KEY=value1:value2

Now that you know the general syntax, there are some crucial points to keep in mind:

  • The names you use for the variables are always case-sensitive. You should know that by convention, all the environment variables must feature names in the UPPER CASE.
  • When you wish to assign a number of values to the concerned variable, you should always separate those by using the colon character right before the following number.
  • Usage of space around the (equals to) “=” symbol is restricted.

Listing Environment Variables

Using several commands, you can list and set environment variables with no issues whatsoever. Let’s have a quick look at those.

  • env command: As already mentioned, the env command is one of the simplest ways to grab the list of environment variables. Apart from that, this command helps permit users to invoke any other desired program within the custom environment. Not just the usual program-running scene, but the same can be done without altering or bringing modifications to the current one. 
  • printenv: I’ve already talked about the printenv command and how it aids in printing either all or the desired environment variables.
  • set: Just what the same suggests, the set command allows you to set or unset the shell variables within your system. Usually invoked alongside arguments, it simply puts forward a list of all the available variables when used without an argument. The list includes both the environment and shell variables and also the shell functions.
  • unset: In case you want to delete the shell and environment variables, the unset command will help.
  • export:  The export command is yet another brilliant command-line utility with which you can easily set environment variables.

Some Common Environment Variables

Having talked a lot about system environment variables, you already know that there are many. Although it isn’t possible to discuss each, I can help discuss some of the most common ones.

  • USER: It defines the currently logged-in user.
  • HOME: With HOME, you’re looking at the current user directory.
  • EDITOR: The EDITOR variable highlights the default file editor. In other words, it is the editor which you generally use for editing pieces of stuff inside the Terminal.
  • SHELL: It defines the path of the current user’s shell. The same can be bash or zsh.
  • LOGNAME: LOGNAME is nothing but the name of the system’s current user.
  • PATH: It signifies the list of directories that need to get searched if and when executing commands is the primary task. When you tend to invoke any command inside the Terminal, the system will head over and look for the concerned directories as uses as per the order executable.
  • LANG: It is settings for the current locales.
  • TERM: TERM is the emulation for the current Terminal.
  • MAIL: Location where the mail for the current user is stored.

How to Show PATH of Environment Variables on Linux

If you want your system to display the path information, just use the printenv command. For printing out the PATH information, invoke the printenv command alongside the name of the environment variable you’re after. Suppose you want to print the PATH information for HOME; run the following command:

$ printenv PATH HOME
Show PATH of Environment Variables

Output:

Alternatively, you can use the echo command and print out the PATH information of the environment variable.

Input:

$ echo $PATH
Show PATH of Environment Variables

With that, I’m done guiding you on how to show PATH of environment variables on Linux. If you’ve read the entire article, you know the significance of printenv and env commands and their respective usage to show PATH of environment variable.

If this guide helped you, please share it.

Leave a Reply
Related Posts