Linux How To Set Environment Variables?
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. Temporary: Open a terminal and enter the command:
export VARNAME=”VALUE“
2. Permanent: Open ~/.profile in your favorite text editor and add:
VARNAME=”VALUE“
3. System wide:
Edit the file /etc/environment, and add the line:
VARNAME=”VALUE“
4. For running scripts:
Create a script that contains commands to set environment variables, such as:
#!/bin/bash export VARNAME=”VALUE“
1. Edit the /etc/environment file:
sudo nano /etc/environment
2. To set a single environment variable, use the export command:
export VARIABLE_NAME=”value”
3. To set persistent environment variables, edit the ~/.bashrc file:
nano ~/.bashrc
4. To set environment variables for a single user, edit the ~/.profile file:
nano ~/.profile
5. To set environment variables system-wide, add the variable to the /etc/profile file:
sudo nano /etc/profile