Permanent PATH variable

227,078

Solution 1

They are configuration files. One way:

  • Open a terminal window using Ctrl+Alt+T
  • Run the command gedit ~/.profile
  • Add the line

    export PATH=$PATH:/media/De\ Soft/mongodb/bin

    to the bottom and save

  • Log out and log in again

Edit:

A safer way is to use quotes. Doing so is necessary if one or more directories in the original PATH contain spaces. So:

export PATH="$PATH:/media/De Soft/mongodb/bin"

Solution 2

To permanently change PATH you need to make changes to /etc/environment file. Make a backup before editing:

sudo cp /etc/environment /etc/environment.bak
sudo nano /etc/environment

sample output:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

Paths are delimited by : so to add a new path say x/y/z this will how our /etc/environment looks like:

PATH="x/y/z:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

Solution 3

Type the following in a terminal window

export PATH=/media/De\ Soft/mongodb/bin:$PATH 

Close the terminal and restart the computer. The path should include /media/De\ Soft/mongodb/bin when you type this in the terminal:

echo $PATH
Share:
227,078

Related videos on Youtube

Towhid
Author by

Towhid

Software Engineer. Love logic. Love to be logical. Love old country song.

Updated on September 18, 2022

Comments

  • Towhid
    Towhid over 1 year

    How will I make this /media/De Soft/mongodb/bin PATH variable permanent?

    Everyone is saying "export PATH=$PATH:media/De\ Soft/mongodb/bin to your ~/.profile, or .bashrc, or .zshenv depending on your shell".

    I don't know what is ~/.profile, or .bashrc, or .zshenv. What do they do actually?

    How will I add export PATH=$PATH:my/path to my .profile/.bashrc/.zshenv?

    I'm using 64 bit Ubuntu 14.04 LTS with default terminal.

  • Nivedita Velagaleti
    Nivedita Velagaleti over 7 years
    agreed. but upon system restart it is loaded in the path variable.
  • yuranos
    yuranos about 7 years
    @GunnarHjalmarsson, do I really need to export PATH var? Maybe, it is done by default in some other script? I have checked by ~/.profile and a PATH var is there, but it is not explicitly exported: PATH=~/.local/bin:$JAVA_HOME/bin:$PATH
  • Gunnar Hjalmarsson
    Gunnar Hjalmarsson about 7 years
    @yuranos87: No, you are right; when modifying PATH in ~/.profile, exporting is redundant, since PATH already is an environment variable.
  • Gunnar Hjalmarsson
    Gunnar Hjalmarsson about 7 years
    @NiveditaVelagaleti: No it's not unless you make it persistent via a config file. The terminal command does not modify PATH persistently.
  • timbo
    timbo almost 7 years
    You don't need to logout and login again. Use source ~/.profile.
  • Gunnar Hjalmarsson
    Gunnar Hjalmarsson almost 7 years
    @timbo: That does not make the variable available to already started processes in the session (except for the current terminal).
  • Bruno Bentzen
    Bruno Bentzen over 5 years
    Don't you need a quote mark in the string as in export PATH="$PATH:/media/De\ Soft/mongodb/bin"? Is it optional?
  • Gunnar Hjalmarsson
    Gunnar Hjalmarsson over 5 years
    @BrunoBentzen: Good question. I edited the answer to clarify.
  • NaturalDemon
    NaturalDemon over 3 years
    Hi, i did what you wrote here and $ echo $PATH reveals: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin‌​:/snap/bin but: sudo nano /etc/environment reveals alot more. like games, i edited the path file, it shows up in NANO, but not in terminal using $echo $PATH, am i alrite?
  • Xaqron
    Xaqron over 3 years
    @NaturalDemon: It doesn't matter how you did that as long as PATH variable contains it correctly you are OK.
  • Admin
    Admin almost 2 years
    To be clear, I should not put this in ~/.bashrc or ~/.bash_profile if I want he variable (PATH) to be available to most applications, correct? The documentation says, "Shell config files such as ~/.bashrc, ~/.bash_profile, and ~/.bash_login... may work on Bash shells for programs started from the shell, [but] variables set in those files are not available by default to programs started from the graphical environment in a desktop session."