Where to add path in /etc/profile

The install instructions tell me to add this line
export PATH=$PATH:/usr/local/go/bin

to /etc/profile

Here is that file: Could someone show me where exactly I should put this line?

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

The if and the fi form blocks, just leave them as they are.

You can just add the line

PATH=/usr/local/go/bin:$PATH

as the last line of /etc/profile.

But do you really want to make Go available for everybody on your Ubuntu(?) system? It should be enough to just make Go available for you. Edit $HOME/.profile for this and append the above line to this file.

Cool, thanks. I added it to my .profile instead. From an inclusion standpoint, I think there are probably many newer developers and even seasoned ones without much Linux know-how that would benefit from a simple addition “append to end of file:yum:

Also maybe a hint(like the one you just gave me) to both the implications of a system-wide/user-only installation and the standard/recommended way to do it?

I watched a video that recommended I add it to my .bashrc. I am having trouble understanding if there would be any functional difference between adding to .bashrc vs .profile. If you could help with that too I’d appreciate it.

It’d also be nice for a reminder that you should restart your Linux machine for the path update to take effect! I just learned that a few days ago, and probably would have been a little frustrated till I googled the problem fix.

Bashrc is only for a login shell using bash. Profile can be seen by “everything”.

You don’t really need this, you can simply execute

source /etc/profile

This will only work in the current terminal. You need to log out and log in to pick the change up for the user or reboot the system to pick it up for everything.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.