Add Environment Variables in Ubuntu

In Ubuntu, you can add environment variables by editing user configuration files or system configuration files.

  1. Edit user configuration file: Open the terminal and enter the following command to open the user configuration file:
  2. Open the file named “.bashrc” in the nano text editor.
  3. Add new environment variables at the end of the file, for example:
  4. Add the directory path to the existing PATH variable.
  5. Press Ctrl + X, type Y to save the changes, and then press Enter to exit the editor.
  6. To make the changes take effect, enter the command below to refresh the configuration.
  7. execute the .bashrc file
  8. You can verify if the environment variables have been successfully added by using the command echo $PATH.

To add environment variables for all users, you can edit the system configuration file.

  1. Open the terminal and enter the following command to open the system configuration file as an administrator:
  2. Open the /etc/environment file with root privileges using the text editor nano.
  3. Add new environment variables to the file, for example:
  4. The PATH variable has a list of directories where executable files can be found.
  5. Press Ctrl + X, type Y to save changes, and then press Enter to exit the editor.
  6. Restart the system or log out and log back in to apply the changes.

In this way, you have successfully added the environment variable.

bannerAds