Permanent PATH variable
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
Related videos on Youtube
Towhid
Software Engineer. Love logic. Love to be logical. Love old country song.
Updated on September 18, 2022Comments
-
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 over 7 yearsagreed. but upon system restart it is loaded in the path variable.
-
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 about 7 years@yuranos87: No, you are right; when modifying
PATH
in~/.profile
, exporting is redundant, sincePATH
already is an environment variable. -
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 almost 7 yearsYou don't need to logout and login again. Use
source ~/.profile
. -
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 over 5 yearsDon't you need a quote mark in the string as in
export PATH="$PATH:/media/De\ Soft/mongodb/bin"
? Is it optional? -
Gunnar Hjalmarsson over 5 years@BrunoBentzen: Good question. I edited the answer to clarify.
-
NaturalDemon over 3 yearsHi, 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 over 3 years@NaturalDemon: It doesn't matter how you did that as long as
PATH
variable contains it correctly you are OK. -
Admin almost 2 yearsTo 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."