How To Add Environment Variable In Linux Permanently?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
1. Open the terminal and type ‘sudo gedit /etc/environment’.
2. Make sure you are logged in as root.
3. This will open the environment file. Here you can add your environment variables.
4. Once you have added the environment variables, save the file.
5. Finally, type ‘source /etc/environment’ to reload the environment file and make the environment variables permanent.
1. Open the /etc/profile or ~/.bash_profile file in any text editor:
sudo nano /etc/profile
2. Add the line containing the environment variable at the end of the file:
export VARIABLE=”value“
3. Save and close the file.
4. To make the change permanent, reload the environment variables using the source command:
source /etc/profile
1. You can use the export command to set environment variables permanently in Linux. The syntax is:
export VARIABLE_NAME=”value”
2. Once you set the environment variable with the export command, it will remain persistent until the next time you log in to your system.
3. To make environment variables persistent across all sessions, edit the /etc/environment file. This file contains variables that are accessible to all users on the system.
4. To add a new environment variable, open the file in a text editor and add a line with the following syntax:
VARIABLE_NAME=”value”
5. Save and close the file. Then run the source command to reload the environment file:
source /etc/environment
6. Verify that the new environment variable has been added by running the echo command:
echo $VARIABLE_NAME