I'm using Homebrew on Mac OS X 10.8.3. Homebrew wants the /usr/local/bin directory earlier in the PATH than /usr/bin, otherwise system-provided programs will be used instead of Homebrew managed replacements.
I'm using zsh, and in my .zshenv I reset the PATH, and then use path_helper to initialize it, like so:
if [ -x /usr/libexec/path_helper ]; then
PATH=''
eval `/usr/libexec/path_helper -s`
fi
Immediately following this, also in .zshenv, I prepend /usr/local/bin to the PATH.
export PATH="/usr/local/bin:$PATH"
There are various other additions to $PATH. RVM, /usr/local/sbin and my personal bin directory:
export PATH=$HOME/.rvm/bin :$PATH
...
export PATH=$PATH:/usr/local/sbin:$HOME/bin
Finally, I use typeset -u to remove any duplicates (although where they are coming from is a mystery to me) from the PATH.
typeset -U PATH
After all of this here is what my PATH looks like:
/Users/mark/.rvm/gems/ruby-1.9.3-p374/bin
/Users/mark/.rvm/gems/ruby-1.9.3-p374#global/bin
/Users/mark/.rvm/rubies/ruby-1.9.3-p374/bin
/Users/mark/.rvm/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/usr/local/sbin
/Users/mark/bin
I know that /etc/paths sets these paths:
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
so I edited that file and removed the /usr/local/bin' option so that the only place it is being set is in.zshenv`.
All of this is contained in my dotfile repository on GitHub (https://github.com/zan5hin/dotfiles), and is being used on two laptops. On the first laptop the path is correct, with /usr/local/bin immediately following the RVM entries. On the second laptop it appears as I detailed above.
I am at a loss to explain why the path is incorrect on the second machine when the zsh configuration is an identical copy.
Can anyone suggest why the path would be out of order?
Thanks.
zsh reads the files in the following order (from man 1 zsh)
$ZDOTDIR/.zshenv
/etc/zprofile (if login)
$ZDOTDIR/.zprofile (if login)
/etc/zshrc (if interactive)
$ZDOTDIR/.zshrc (if interactive)
/etc/zlogin (if login)
$ZDOTDIR/.zlogin (if login)
If ZDOTDIR is unset, HOME is used instead. Files listed above as being in /etc may be in another directory, depending on the installation.
Your changes were to (1) which is before (2); the macOS default for (2) is:
% cat /etc/zprofile
# System-wide profile for interactive zsh(1) login shells.
# Setup user specific overrides for this in ~/.zprofile. See zshbuiltins(1)
# and zshoptions(1) for more details.
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
thus, your changes are being overridden by the macOS default. You will need to make your PATH changes later in the pipeline in order to preserve order.
This line is wrong:
export PATH=$HOME/.rvm/bin :$PATH
It should be:
export PATH=$HOME/.rvm/bin:$PATH
The space before :$PATH is causing you to lose the previous contents of $PATH.
Related
after the installation following the instructions with
curl https://nixos.org/nix/install | sh
and logout/login, nix-env and nix-build are not found.
I had the problem with debian stretch and now with buster. What am I doing wrong?
The nix manual instructs to execute
source ~/.nix-profile/etc/profile.d/nix.sh
but the instructions printed after the execution say to do (I do not remember exactly)
./~/.nix-profile/etc/profile.d/nix.sh
and the same command is inserted into ~/.profile. The cause of the problem is the difference between . and source (see this superuser question). The script is setting up the $PATH variable in the environment and has the desired effect wtih source but no effect with . (which operates in its own shell and closes it at the end).
Cure:
change the line in .profile (or better move it to .bashrc) to
if [ -e /home/xxx/.nix-profile/etc/profile.d/nix.sh ]; then source /home/xxx/.nix-profile/etc/profile.d/nix.sh; fi
(xxx is your user name),
You need to add this recommended script.
For me only setting $PATH like this worked (in .profile)
export PATH="$PATH:/nix/var/nix/profiles/default/bin"
I'm trying to extend my $PATH variable in git bash (MinGW shell) by adding the following to the file ~/.bashrc
PATH=$PATH':/c/Program Files/maven/apache-maven-3.2.5/bin'
After I did this and restarted the bash it seems like that the $PATH variable was extended like expected:
$ echo $PATH
MANY_OTHER_PATHS:/c/Program Files/maven/apache-maven-3.2.5/bin
But I still cannot execute the programms in the given directory:
$ mvn
bash: mvn: command not found
What went wrong here? How do I extend the PATH variable correctly?
Here are two ideas.
You can have your path with double quote mark.
export PATH=$PATH:"/C/Program Files (x86)/apache-maven-3.3.3/bin"
Or, You can also make symbolic link for the directory.
ln -s "/C/Program Files (x86)/apache-maven-3.3.3/bin" ./mvnbin
export PATH=$PATH:/your-path/mvnbin
It works for me in mingw32 environment.
I needed to add something to my Git Bash path permanently each time I open it. It was Meld.exe path which can be added with:
export PATH=$PATH:"/C/Program Files (x86)/Meld/lib"
In order to execute this command each bash session, you need a ~/.bashrc file. Check if it already exists or create it using notepad ~/.bashrc or touch ~/.bashrc.
You can check where it is with:
echo ~
Open it and add the command that adds the PATH (first command in this response).
I hope you found this useful.
According to this SO post, you need to escape Program Files with quotes. git-bash $PATH cannot parse windows directory with space
Add PATH in Git Bash Permanently | Windows Only
Just in case you are still wondering how to add a path permanently in git bash here is the step-by-step process for Windows users:
Create .bashrc in user's root folder using the below command. It will open notepad and ask you to create the file, click yes.
notepad ~/.bashrc
Put the directory you want to add as below, for more than 1 items repeat the same format in next line:
export PATH=$PATH:"/c/folder/folder/"
Save the file and relaunch the bash.
Next launch will give you a warning like WARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile. but git bash will handle it by creating the required files.
SOME INSIGHTS
Git Bash doesn't fetch Window's environment PATH, it maintains its PATH separately in more like a Linux way.
You can run export PATH=$PATH:"/c/folder/folder/" in cmd to add a directory to path, but it will be only for the current session once you close the bash, it will be gone.
.bashrc is a shell script file that will be executed every time you launch a new git bash window. So you can add any type of bash command here. We simply added the export command to add our desired directory to PATH.
So I'm trying to add TeX Live to my PATH and I couldn't be more confused.
(For the record, I'm using iTerm and oh-my-zsh on Mac OS X)
In my .zshrc file, my path looks like this:
# Path to MAMP PHP
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin
# Path to LaTeX
export PATH=/usr/local/texlive/2014basic/bin/x86_64-darwin:$PATH
After adding the last two lines, my iTerm starts with errors looking like:
/Users/zach/.zshrc:17: command not found: killall
/usr/bin/env: zsh: No such file or directory
box_name:1: command not found: hostname
and more...
My /etc/paths file looks like
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/usr/local/texlive/2014basic/bin/x86_64-darwin
However, after ALL of this, echo $PATH just returns:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Please help me...I am getting so frustrated. All I want to be able to do is run tlmgr.
You did not included full .zshrc so hard to figured out what is going on, but I guess that in first line you rather want
PATH=$PATH:/Applications/MAMP/bin/php/php5.5.10/bin
Otherwise you wouldn't be able to call any commands directly from e.g. /usr/bin, and messages like "command not found" only confirm my suspicion.
I'm using Mac OS X, iTerm2, zsh and Tmux via Homebrew. When I start a Terminal session in iTerm2, the global PATH variable looks still fine. But when I open up a Tmux session the PATH variable is extended with the same paths it already consisted of. I'm going to put a issue solving code snippet in my .zshrc, but I'm still interested in the cause why the PATH variable is filled up twice.
This happens because your .zshrc is evaluated for every new zsh process. So when you start iTerm2 it gets evaluated making your changes to $PATH, then when you start tmux that gets your modified $PATH and passes it on to a new instance of zsh inside of there and that new zsh process again evaluates the .zshrc making the changes again.
There are several ways that you could prevent this.
$TMUX
First, to specifically prevent it from happening for shells inside of tmux you could skip making those changes if $TMUX is set:
if [[ -z $TMUX ]]; then
PATH="$PATH:/foo"
fi
zprofile
Another option would be to move that portion of your .zshrc to your .zprofile file. This file is only evaluated by login shells. But, by default tmux starts new shells as login shells, so you'd also need to prevent tmux from doing that by adding the following to your tmux configuration:
set -g default-command /bin/zsh
You may need to adjust the path to zsh there. This would prevent tmux from starting zsh processes as login shells, so zsh inside of tmux wouldn't look at the .zprofile.
typeset
Another option somewhat along the lines of the code snippet that you linked to for preventing duplicates to be added would be to change your path modification to be something like:
typeset -aU path
path=( $path /foo )
This works because zsh automatically sets up the $path variable as an array that mirrors the content of $PATH. The -U option to typeset modifies that variable so that the entries are unique.
I found this GitHub thread very useful. The solution from this comment worked for me:
# /etc/zshenv
if [ -x /usr/libexec/path_helper ]; then
PATH="" # Add this line
eval `/usr/libexec/path_helper -s`
fi
By doing this, you'd have to put your PATH modifications in ~/.zshrc instead of ~/.zprofile. I also tried this solution from the thread but didn't work for me.
My solution:
Step 1:
In .bashrc or .zshrc
ExtraPath="/foo/bar:$HOME/bin" # your customized path here, /foo/bar and $HOME/bin for instance
if ! [[ "$PATH" =~ "$ExtraPath" ]] ; then PATH="$ExtraPath:$PATH" ; fi # if the PATH does not contain your customized path, then insert yours, else do nothing.
Step 2:
in ~/.tmux.conf, add
set -g default-command "${SHELL}"
in this case, tmux will not source /etc/profile, so it will not mess up with your PATH
I was trying to set up a bash command in Terminal on a Mac.
The scripts run correctly when I execute them directly.
I set up symlinks in /usr/local/bin/ to the current location of the scripts. When I try to run it off the symlink, it doesn't work. I don't believe the issue is the $PATH, because pip, git, ipython all exist in this location. When I edit the $PATH setting, these fail.
Suggestions?
ls -l /usr/local/bin/foo and see where your symlink is actually pointing. Betcha it's broken.
If not, try running /usr/local/bin/foo. If that works, it was your PATH that's wrong, despite what you said in the OP.
The only other thing that would cause this behavior is if the script is reading $0 (its own name as executed). With a symlink, that will have a different value.
I found my own answer... The symlinks were created by an automated file which was gabbing my pwd. I was also using virtualenv, so to get it to work, I had to activate the virtualenv and be inside the folder that had the script that created the symlinks.
I install my commands in $HOME/bin instead of /usr/local/bin, but it does not matter much. As hinted in the comments, one question is whether the symlinks are set correctly.
Check which command the shell thinks you should execute: which command
Check that the link in /usr/local/bin points to the correct file (and has execute permission, etc):
ls -l /usr/local/bin/command
ls -lL /usr/local/bin/command
Check that the interpreter path in the shebang is correct:
file /usr/local/bin/command
Check that /usr/local/bin is actually on your PATH: echo $PATH
If none of that shows up a problem, show us the results of the commands above.