Setting PATH environment variable

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
capngp
Level 1
Level 1
Posts: 6
Joined: Wed Feb 01, 2012 2:13 pm

Setting PATH environment variable

Post by capngp »

I feel silly asking such a basic question, but I can't seem to find where the PATH
variable gets set in Mint 17 when I fire up a terminal session. It should be in
.bash_profile, but I don't seem to have that file in my HOME directory. User manual
says nothing, archive search turned up nothing.

User avatar
WharfRat
Level 21
Level 21
Posts: 13770
Joined: Thu Apr 07, 2011 8:15 pm

Re: Setting PATH environment variable

Post by WharfRat »

If you need to change your $PATH, create the file ~/.bashrc and add the lines

Code: Select all

PATH="$HOME/somedir:$PATH"
What I do is add aliases and functions to a file and source then in ~/.bashrc

Code: Select all

if [ -d "$HOME/script" ] ; then
    PATH="$HOME/script:$PATH"
fi
#
if [ -e "$HOME/.functions" ] ; then
	. $HOME/.functions
fi
#
if [ -e "$HOME/.aliases" ] ; then
	. $HOME/.aliases
fi
Good luck
ImageImage

Mute Ant
Level 14
Level 14
Posts: 5132
Joined: Tue Sep 03, 2013 7:45 pm
Location: Norfolk UK

Re: Setting PATH environment variable

Post by Mute Ant »

You can totally destroy your system security here...
/etc/login.defs
  • # *REQUIRED* The default PATH settings, for superuser and normal users.
    # (they are minimal, add the rest in the shell startup files)
    ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
The .bashrc is much safer, your changes get forgotten at log out.

BONUS ANSWER
You find stuff like this by searching for files that contain juicy text. In this case, i guessed somewhere in /etc/ and "PATH="

Code: Select all

find 2>/dev/zero /etc -type f | while read a ; do grep 2>/dev/zero -l "PATH=" "$a" ; done
...and then guess which file is relevant.
While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named "manual".

capngp
Level 1
Level 1
Posts: 6
Joined: Wed Feb 01, 2012 2:13 pm

Re: Setting PATH environment variable

Post by capngp »

For those interested, the PATH variable is set in /etc/environment in Linux Mint 17.
It is R/O for anyone not root.

jonas-e
Level 3
Level 3
Posts: 113
Joined: Tue Apr 09, 2013 1:20 am
Location: Copenhagen, Denmark
Contact:

Re: Setting PATH environment variable

Post by jonas-e »

I googled this and found loads of different confusing ways to add values to e.g. PATH. The options on the command line using export and = only last within that terminal session. The last suggestion in this thread seems simplest to me - and it seems to work. Open /etc/environment as root with a text editor:

Code: Select all

sudo gedit /etc/environment
Add the desired variable in the text file separated by colon, save, logout, login - and it is permanently and globally changed - if that's what you want. In my case added the AndroidSDK path:

Code: Select all

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/etc/android-sdk/android-studio-ide-135.1641136-linux/bin/

Post Reply

Return to “Newbie Questions”