How Do I Set an Environment Variable in Linux Bash?
Contents

The easiest way to set environment variables in Bash is to use the “export” keyword followed by the variable name, an equal sign and the value to be assigned to the environment variable.

How do I set environment variables in bash?

3.2 How to Set an Environment Variable Permanently in Bash Shell

  1. Use ” printenv ” (or ” env “) to list all the environment variables.
  2. Use ” setenv varname value ” and ” unsetenv varname ” to set and unset an environment variable.

How do I set an environment variable in Linux terminal?

To make an environment persistent for a user’s environment, we export the variable from the user’s profile script.

  1. Open the current user’s profile into a text editor. vi ~/.bash_profile.
  2. Add the export command for every environment variable you want to persist. export JAVA_HOME=/opt/openjdk11.
  3. Save your changes.
Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest