Add Environment Variables in Ubuntu
In Ubuntu, you can add environment variables by editing user configuration files or system configuration files.
- Edit user configuration file: Open the terminal and enter the following command to open the user configuration file:
- Open the file named “.bashrc” in the nano text editor.
- Add new environment variables at the end of the file, for example:
- Add the directory path to the existing PATH variable.
- Press Ctrl + X, type Y to save the changes, and then press Enter to exit the editor.
- To make the changes take effect, enter the command below to refresh the configuration.
- execute the .bashrc file
- 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.
- Open the terminal and enter the following command to open the system configuration file as an administrator:
- Open the /etc/environment file with root privileges using the text editor nano.
- Add new environment variables to the file, for example:
- The PATH variable has a list of directories where executable files can be found.
- Press Ctrl + X, type Y to save changes, and then press Enter to exit the editor.
- Restart the system or log out and log back in to apply the changes.
In this way, you have successfully added the environment variable.