Linux 101: What are Environment Variables?


Jack Wallen introduces you to Linux environment variables. What are they and how are they set and not set?

Image: Jack Wallen

How many times have you installed something on Linux only to find out you need to set certain environment variables before the installation works? It happens to me all the time.

But what are these environment variables and how do you set them? Let’s dive in and find out.

SEE: Rust: What Developers Need To Know About This Programming Language (Free PDF) (TechRepublic)

The first thing you should know is what environment variables are. In simple terms, environment variables are a set of dynamic named values ​​that are stored in the system and used by applications. You can use these variables to customize how certain applications and services behave with the system. Each variable contains a name and an associated value. Usually the name is in UPPER CASE and the values ​​are of course case sensitive.

For example, let’s say you install the Go language on Linux. Because of the way Go is installed, you need to tell the system where the executable binaries are located. Most of the time these files are in / usr / local / go / bin. But if you just download and extract Go to / usr / local / go, your system (and bash shell) won’t know these files are there. To fix this you need to set an environment variable.

Obviously, you can just add / usr / local / go / bin to your $ PATH which is the traditional way of solving this problem. But let’s say you want to do this temporarily. You can set and then cancel the environment variable. First, let’s set GO_PATH as / usr / local / go / bin. To do this, we use the export command as in export GO_PATH = / usr / local / go / bin. Issue the command echo $ GO_PATH and you will see that / usr / local / go / bin has been set successfully.

SEE: 5 Linux Server Distributions You Should Use (TechRepublic Premium)

Now, if you wanted to use the path for Go in a script, you could include $ GO_PATH in place of / usr / local / go / bin. This new variable is available system-wide and is inherited by all created child processes and shells. To override this environment variable, you would issue the command Cancel GO_PATH.

You can also list all of your currently set environment variables with the command to adjustlisting a lot of variables.

Environment variables are very useful when used in scripts and sometimes need to be set manually when installing certain software. Use them now to make Linux and the Linux command line even more efficient.

Subscribe to TechRepublics How to get tech up and running on YouTube for the latest technical advice to business professionals from Jack Wallen.

See also

Source link


Leave A Reply