3

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.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
DBS
  • 162
  • What command did you use to modify your PATH variable? – cremefraiche Apr 16 '15 at 21:38
  • @cremefraiche I used gksudo gedit /etc/environment and then added "/opt/texbin" 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
  • @DBS The obvious question is - what did you do after changing your path? Did you reboot? In any case, as cremefraiche says, changing system files in this fashion is not recommended. Change your ~/.bashrc or similar. What do you need the /opt/texbin for? – Faheem Mitha Apr 16 '15 at 22:05
  • @FaheemMitha After changing my path I rebooted. I tried changing the bashrc but it didn't work. I was trying to install Tex in my system follwoing the second answer here http://tex.stackexchange.com/questions/1092/how-to-install-vanilla-texlive-on-debian-or-ubuntu/95373#95373 – DBS Apr 16 '15 at 22:16
  • The point is my terminal cannot access latex unless I add it to the PATH this is where the problem is. – DBS Apr 16 '15 at 22:16
  • @DBS what is your distribution? Why not use binary packages for your distribution? I'm a bit puzzled by that particular instruction. /etc/profile is where Debian/Ubuntu sets PATH. – Faheem Mitha Apr 16 '15 at 22:18
  • If you look at the comments, a couple of people say that /etc/environment does not work, and I don't see why it should. See also http://tex.stackexchange.com/questions/1092/how-to-install-vanilla-texlive-on-debian-or-ubuntu/95373#comment437238_95373 However, I recommend you just use ~/.bashrc. I personally use the TeX Live binary packages though. – Faheem Mitha Apr 16 '15 at 22:25
  • @FaheemMitha thank you for your answers. here is what I have Description: Ubuntu 14.04.2 LTS. I tried modifying my ~./bashrc file but it is not working. Does it have something to do with running linux over chrome using crouton? – DBS Apr 18 '15 at 12:28
  • When you say "but it is not working" what do you mean, exactly? What did you do after you modified the ~/.bashrc? – Faheem Mitha Apr 18 '15 at 18:04
  • Well I rebooted again started shell and (ctrl+ alt+ t) and typed $PATH the changes weren't there. when I typed which latex the shell prompt didnt respond. – DBS Apr 19 '15 at 10:13

4 Answers4

3

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:

Kusalananda
  • 333,661
0

update note: I wrote this for zsh but it works for bash as well.

Here is a trick I use to keep my path clean. (Note: I load in zsh configs as separate files. This file needs to load first so an easy way to force that while maintaining standardized naming conventions is to use prefixes. Prefixing with 0_pathfix.zsh will cause this to run before the other Zsh config files.)

# add to path if $1 is not already in path
pathAppend() {

if ! echo $PATH | egrep -q "(^|:)$1($|:)" ; then PATH=$PATH:$1 fi }

filters the path checking against itself for duplicates returns clean path then exports the clean path.

PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++{if (NR > 1) printf ORS; printf $a[$1]}'); export PATH;

This ensures that even if you manually added to the path the next time zsh source is reloaded the path will clean itself.

sloshy
  • 39
0

/etc/environment is the system wide fallback. The per-user config in ~/.bash_profile probably overrides it. Regardless, don't mess with /etc/environment for configuring bash, instead put whatever PATH you want in ~/.bash_profile. Even if /etc/environment is wrong it will be overridden by what you put in ~/.bash_profile.

You should probably also restore /etc/environment to what it was before to avoid minor breakage with programs that depend on it. That file comes with the package, so you can use your package manager to reset it to its original form.

Bagalaw
  • 945