2

When I type echo $PATH, I get the output:

/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

However, I modified my PATH variable using gksudo gedit /etc/environment; the file now reads PATH="/opt/texbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games".

I am not sure why I am getting two different value of PATH. How can I fix it?

I am running Xfce on a Chromebook using Crouton.

  • What command did you use to modify your PATH variable? – cremefraiche Apr 16 '15 at 21:38
  • @cremefraiche I used <code> gksudo gedit /etc/environment </code> and then added <code> "/opt/texbin"</code> saved it rebooted but still the same problem. – DBS Apr 16 '15 at 21:40
  • 7
    That is not the way you should be changing your path variable. If you are trying to change the PATH variable for the current user only, modify the line in ~/.bashrc that says export PATH=$PATH:.... All you need to do is add a colon to the end and include the path. Example: export PATH=$PATH:...:/new/path – cremefraiche Apr 16 '15 at 21:44
  • @cremefraiche thanks let me try that. Btw would you explain why editing the PATh in /etc/environment doesnt work? – DBS Apr 16 '15 at 21:46
  • 2
    From what I understand it is best not to mess with that file directly, in order to minimize risk of breakage. I should mention that ~/.bashrc is run every time an interactive shell is opened, while ~/.bash_profile is run when a login shell is opened. Pick which file best suits your needs. – cremefraiche Apr 16 '15 at 21:54
2

Edit

  • /etc/profile to affect all users.
  • ~/.bash_profile to affect single users bash shell (so not this one, as it is for bash specific stuff).
  • ~/.profile to affect single user, all shells.

Note: If you have both .profile and .bash_profile and you want both to be read by bash, then you will have to add . .profile to your .bash_profile, as .profile is not read by default, if .bash_profile exists

on sudo

  • don't run your editor as root, so don't do gksudo gedit «filename»
  • Avoid running X11 apps as root, so don't do gksudo gedit «filename»
  • instead do EDITOR=gedit sudoedit «filename». It will run the editor as you on a temporary file, it will copy the fill as root when you finish.
1

The correct place to set your PATH is in ~/.bash_profile:

PATH="$PATH:/some/extra/paths:/may/go/here"

The PATH variable should already be exported, so you shouldn't need to export it again (exporting it again has no further effect).

The default path for bash is hardcoded into the bash executable, and then further (possibly) modified in /etc/profile and (on some systems) /etc/bash.bashrc.

My guess is that the path set in /etc/environment is primarily used by non-shells, such as cron etc.

See also:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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