I am completely new to Ubuntu, and I would permanently set an environment variable.
I have read here that I have to set ~/.profile, but I don't know how to apply it. In my case I would permanently set export PATH="/home/name/anaconda/bin:$PATH", how could I do?
Asked
Active
Viewed 1.5e+01k times
49
Simone
- 593
- 1
- 4
- 8
-
2@Zanna I think this is more useful (having used it myself): [How do I set PATH variables for all users on a server?](http://askubuntu.com/questions/24937/how-do-i-set-path-variables-for-all-users-on-a-server). At least because the `environment` answer is the most upvoted one there :) – Gallifreyan Feb 26 '17 at 10:41
-
From ubuntu docs here: https://help.ubuntu.com/community/EnvironmentVariables#System-wide_environment_variables – vpedrosa Feb 26 '17 at 13:20
-
1@vpedrosa: Since the folder to be added to PATH is in $HOME, it's unlikely that modifying PATH system wide applies here. – Gunnar Hjalmarsson Feb 26 '17 at 14:32
-
I had similar issue with GOPATH environment variable. I had to put export GOPATH="$HOME/path/to/workspace/", and then log back to apply the edited file – MinhajulAnwar Aug 19 '18 at 16:30
1 Answers
58
- Open a terminal window with Ctrl+Alt+T.
Open the file for editing with
gedit ~/.profileAdd the command to the bottom of the file.
Save and close gedit.
Log out and log in again.
Gunnar Hjalmarsson
- 32,938
- 3
- 63
- 94
-
Do I have to add the entire command `export PATH="/home/name/anaconda/bin:$PATH` at the bottom of the file? Or I have to add it at the existing PATH? – Simone Feb 26 '17 at 14:04
-
1@Simone: You should add the entire command. That way you do add the folder to the existing PATH. (Don't forget the trailing `"`, btw.) – Gunnar Hjalmarsson Feb 26 '17 at 14:24
-
-
-
@GunnarHjalmarsson If I update the ~/.profile file for one particular user the variable doesn't get updated for other users. (Or are environment variables user-specific only? Are there system-wide/user-independent environment variables?) – akki Jul 07 '17 at 08:26
-
2@akki: Ok, now I see. Yes, you can set them [system wide](https://help.ubuntu.com/community/EnvironmentVariables#System-wide_environment_variables) if you like. – Gunnar Hjalmarsson Jul 07 '17 at 17:10
-
I followed this method, now stuck in an infinite login loop. Any suggestions? – Mobeen Aug 17 '17 at 21:11
-
@Mobeen: Apparently you made a mistake. I suggest that you file a new question where you describe the problem as detailed as you can. – Gunnar Hjalmarsson Aug 17 '17 at 21:55
-
I think user need logout then login to reapply the updated .profile – MinhajulAnwar Aug 19 '18 at 16:27
-
18You don't have to logout and login again. You can simply do `source ~/.profile ` to apply the changes. – Sohaib Farooqi Sep 13 '18 at 10:26
-
2@bro-grammer: Doing so would only apply them in the current terminal window. Already running processes would not be aware of the changes. – Gunnar Hjalmarsson Sep 13 '18 at 13:41
-
Is it correct that if you want to add the vars system wide you can use this profile file: `sudo vi /etc/profile` and add them there? – bersling May 25 '21 at 13:49