Open In App

How to Set Environment Variable in Linux Mint

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

An environment variable in Linux Mint is a dynamic value that affects how processes and applications operate within the system. These variables are key-value pairs stored in the system's memory and are used to pass configuration information to programs. For example, environment variables can define the system's default text editor, file paths, user-specific settings, or even locale information.

Whether you're a developer setting up a project or a user tweaking system configurations, knowing how to manage environment variables in Linux can enhance your workflow. In this guide, we’ll cover the step-by-step process to set environment variables in Linux Mint. From temporary variables to permanent configurations, you'll learn how to leverage this powerful feature effectively.

Types of Environment Variables

Environment variables in Linux Mint are categorized based on their scope and duration. Understanding these distinctions is essential for effectively configuring your system.

System-Wide vs. User-Specific Variables

  • System-Wide: Affect all users and processes, set in files like /etc/environment or /etc/profile.
  • User-Specific: Limited to a specific user, configured in .bashrc, .zshrc, or .profile.

Temporary vs. Permanent Variables

  • Temporary: Exist only during the current session, set with the export command, and lost after logout.
  • Permanent: Persist across sessions, configured in shell files like .bashrc (user-specific) or /etc/environment (system-wide).

Learn here: Enviourment Variables in Linux/Unix

Setting Temporary Environment Variables

Temporary environment variables are defined for the duration of the current shell session or terminal. These variables are volatile, meaning they are removed as soon as the terminal is closed or the system is rebooted. Setting temporary environment variables is straightforward and often used for testing or temporary configurations.

Steps to Set Temporary Environment Variables

1. Using the export Command: The most common method to set a temporary environment variable is by using the export command in the terminal. The syntax is:

export VARIABLE_NAME="value"

Example:

export MY_VAR="TemporaryValue"

This creates a variable MY_VAR with the value TemporaryValue, which is accessible within the current session.

2. Confirming the Variable: After setting the variable, verify its value using the echo command:

echo $MY_VAR

The output will display:

TemporaryValue

3. Using Variables in Commands:Temporary variables can be used directly in commands or scripts during the session. Example:

cp $MY_VAR/filename /destination

You can define and use a variable for just one command by prefixing it before the command:

VARIABLE_NAME="value" command

Example:

LANG="en_US.UTF-8" grep "text" file.txt

Here, the LANG variable is temporarily set only for the grep command.

Viewing Current Environment Variables in Linux Mint

To manage environment variables effectively, it’s crucial to know how to view them. Linux Mint provides several commands to list and inspect these variables.

List All Environment Variables

Use the env command to display all active environment variables:

env

Alternatively, use printenv for a similar output:

printenv

View a Specific Environment Variable

To check the value of a specific variable, use the echo command:

echo $VARIABLE_NAME

Example:

echo $PATH

View Shell-Specific Variables

Use the set command to list both shell and environment variables. This shows additional information compared to env or printenv.

Conclusion

Environment variables are a powerful tool in Linux Mint, enabling users to customize their system and streamline workflows. By mastering the steps to set temporary and permanent variables, you can enhance the functionality of your applications and scripts. Whether you’re testing configurations with temporary variables or making lasting changes with permanent ones, these skills are essential for efficient system management.

Understanding how to view, set, and manage environment variables not only boosts productivity but also helps in troubleshooting and optimizing performance.


Article Tags :

Similar Reads