39

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?

4
  • 2
    @Zanna I think this is more useful (having used it myself): How do I set PATH variables for all users on a server?. At least because the environment answer is the most upvoted one there :) Feb 26, 2017 at 10:41
  • From ubuntu docs here: help.ubuntu.com/community/…
    – vpedrosa
    Feb 26, 2017 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. Feb 26, 2017 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
    – Minhaj
    Aug 19, 2018 at 16:30

1 Answer 1

50
  • Open a terminal window with Ctrl+Alt+T.
  • Open the file for editing with

    gedit ~/.profile
    
  • Add the command to the bottom of the file.

  • Save and close gedit.

  • Log out and log in again.

12
  • 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, 2017 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.) Feb 26, 2017 at 14:24
  • 2
    @akki: Ok, now I see. Yes, you can set them system wide if you like. Jul 7, 2017 at 17:10
  • 15
    You don't have to logout and login again. You can simply do source ~/.profile to apply the changes. Sep 13, 2018 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. Sep 13, 2018 at 13:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.