20

I don't have .bash_profile or .bashrc files and I am definitely using the bash shell. I am using Mac OS X 10.11.1 El Capitan.

How do I permanently modify my $PATH to cut down the default values Apple ships?

bmike
  • 235,889
Dan
  • 736
  • 1
    What have you tried - have you tried creating a .bash_profile and .bashrc (note no _) – mmmmmm Nov 13 '15 at 17:00
  • No I haven't. My $PATH variable is set, though. Where is it getting those settings from? I need to remove something from it. – Dan Nov 13 '15 at 17:01
  • That is a different question - and has been asked many times – mmmmmm Nov 13 '15 at 17:03
  • @Mark link please? – Dan Nov 13 '15 at 17:04
  • I don't think it's necessarily a duplicate of the linked question. I flagged the answer as unclear and the OP should specify what exactly to remove because there are a lot of different methods to add (and remove) paths to (or from) $PATH. – klanomath Nov 13 '15 at 17:38
  • @Mark that only changes it for the session, not permanently. I need to know the location where these path variables come from because they are pointing to places that no longer exist. – Dan Nov 13 '15 at 17:55
  • 1
    @Dan, see http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files -- there are "global" config files that get sourced. – glenn jackman Nov 13 '15 at 17:56
  • Thank you @glennjackman that link solved my issue: "When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable." – Dan Nov 13 '15 at 19:19
  • It was in ~/.profile which I didn't know existed nor to look for. Most tutorials online asking to modify $PATH never mention this file, only the previous two. Thank you. – Dan Nov 13 '15 at 19:21
  • @Dan Well done with the edits. I've nuked most of the temporary comments. Cheers and thanks! – bmike Nov 15 '15 at 19:15

1 Answers1

15

.bash_profile and .bashrc do not have to exist for $PATH to work, they're for bash configuration. According to the bash docs,

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

  • To add a path to your $PATH variable for a single terminal session, do so as follows: export PATH=$PATH:pathToYourDirectory, for multiple directories export PATH=$PATH:pathToYourFirstDirectory:pathToYourSecondDirectory ...

  • To see what's in your $PATH: echo $PATH or cat /etc/paths

  • /etc/paths is the file that holds your system path variables

Run man path_helper for more information.

Dan
  • 736
enzo
  • 1,038