Setting PATH on OS X 10.9 is not working - macos

I have searched all posts regarding PATH issues on Mac, but have not found an answer to mine.
I want to get /usr/local/bin to be searched first. I used homebrews example but it did not work. I created the .bash_profile file and put in:
export PATH="/usr/local/bin:$PATH"
As homebrew says except this seems to remove the standard commands for me with ls, cd, etc not working. I want it to search this folder first. I found the /etc/paths file and saw that it /usr/local/bin is located last.
Following instructions found here not to mess with the path file, I removed the change I made to .bash_profile and was able to get it to work (brew doctor is successful) with putting in
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I have tested this on two different Macs, and neither accepts appending the $PATH. Doing some research it seems that there is a path_helper file which calls stuff which may have changed in OS x 10.9. Is there a way to get the appending to work? I have tried it with the quotes and without and neither works. And each time I have restarted terminal or tried the source ~/.bash_profile command
I would prefer to not rewrite the whole path in .bash_profile, or at least know why appending it is not working.

After some investigation it turns out that the problem may have been how file ~/.bash_profile was created - it may not have been a plain-text file (due to use of TextEdit).
Recreating it with a plain-text editor (Sublime Text) solved the problem.
Follow-up question by the OP:
As for prepending /usr/local/bin without having it appear twice in $PATH:
export PATH="/usr/local/bin:${PATH/:\/usr\/local\/bin/}"
${PATH/:\/usr\/local\/bin/}, using bash's parameter/variable expansion, removes /usr/local/bin, if present, from the existing $PATH.

I had a similar problem after installing homebrew.
In the end, it came down to the fact that brew doctor was suggesting I modify ~/.bash_profile when all my usual (old) settiings were in ~/.profile. If you read the bash manpage though it tells you that bash first reads /etc/profile and then THE FIRST ONE OF ~/.bash_profile, ~/.bash_login, and ~/.profile - not all of them!
What I am saying is to agglomerate all your setttings in ONE of thos e files only.

edit the /etc/paths to look like
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
if it didn't work then add export PATH="/usr/local/bin:$PATH" to the .bash_profile and it should work...

Related

Terminal doesn't work (bash commands aren't recognizable)

I have macOS Sierra version 10.12.6
I tried to add a path using the terminal. I entered source ~/.bash_profile and then a text file opened and I entered my path.
But then the terminal stopped responding and bash commands are not recognizable anymore.
If I enter: source ~/.bash_profile nothing happens.
And if I enter any environment related command an error message shows: -bash: printenv: command not found
How can I fix this?
You've probably messed up your path. When you're setting a path it's important to append to it rather than overwrite, or you lose access to all the system paths; /usr/local/sbin, /usr/local/bin, /usr/sbin etc. When setting a new path make sure you use:
$PATH=$PATH:/path/to/add
You can fix this by removing the line from .bash_profile where you overwrote the path. Please paste the contents of .bash_profile if this does not work.
You've replaced $PATH with some of your values and you might not be able to update .bash_profile because of the unavailability of nano. Use the following command to access nano and environment variables.
export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
After using the command you can use nano ~/.bash_profile to fix the problem.

"reload ~/.bash_profile"error by installing virtualenvwrapper

The virtualenvwrapper official documents ask me to add three lines to ~/.bash_profile, but I add three wrong lines to there, and then, there is an error looks like below after I reloaded by commandsource ~/.bash_profile
/Users/donald/.bash_profile:1: bad assignment
Can anyone tell me how to do and why? and if someone can teach me how to install virtualenvwrapper? I have spent a whole night working on this and fail.
The three wrong command lines are:
export WORKON_HOME=~/Envs
mkdir -p $WORKON_HOME
source /usr/local/bin/virtualenvwrapper.sh
It's just a simple question, I found the answer later.
After you add wrong command lines to .bash_profile , you can use the command lines below to get a easy-editing window
touch ~/.bash_profile
open -e ~/.bash_profile
then you will know how to do.
And...
If you are confused with installing virtualenvwrapper, have a look on this:
virtualenvwrapper.sh is not in /usr/local/bin, you can use the command line below to find where is it.
which virtualenvwrapper.sh
After that, you can copy the virtualenvwrapper.sh to /usr/local/bin or change the path after source command in the .bash_profile.
Remember to reload the .bash_profile with the command line below everytime you use virtualenvwrapper.
source ~/.bash_profile
Thanks~!

Where did I go wrong in virtualenv installation on OSX?

I followed the instructions carefully at http://jamie.curle.io/blog/installing-pip-virtualenv-and-virtualenvwrapper-on-os-x/
Restarted my terminal and typed mkvirtualenv, got a command not found
looked in /usr/local/bin and ls shows me:
brew powerpc-apple-darwin8-gfortran-4.2
charm tclsh8.5
django-admin.py tclsh8.6
django-admin.pyc virtualenv
gfortran-4.2 virtualenv-2.7
gfortran-uninstall virtualenv-clone
i686-apple-darwin8-gfortran-4.2 virtualenvwrapper.sh
node virtualenvwrapper_lazy.sh
pip wish8.5
pip2 wish8.6
So I know it's in the correct directory. I don't understand where I could have screwed up.
The linked article recommends adding the line source /usr/local/bin/virtualenvwrapper.sh to bash login profile file ~/.bash_login.
However,
~/.bash_login is rarely used.
it is NOT read if the much more common (on OS X) ~/.bash_profile also exists.
Thus,
Check if you have a ~/.bash_profile file
and, if so, add the line source /usr/local/bin/virtualenvwrapper.sh there.
My recommendation is to never use ~/.bash_login. If you find other content, there, also add it to ~/.bash_profile, and delete ~/.bash_login.
Alternatively, if you're looking for cross-platform compatibility, put all definitions in ~/.bashrc instead, and add only [[ -e ~/.bashrc ]] && . ~/.bashrc to ~/.bash_profile.

How to properly setup my git $PATH on my mac (I did, but need to understand how it really works)?

I installed GIT from the site on my mac, but git --version gave me the old installation (I guess xcode installation). So I solved doing this:
create a ~/.bash_profile file
write:
export PATH=/usr/local/bin:$PATH
restart the terminal
Though, I think there's something in my configuration I could better setup.
My current echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
So IT WORKS, but it's quite a mess, since I've got 2
/usr/local/bin AND an /usr/local/git/bin
Also, I cannot understand WHY now it works, since /usr/local/bin only contains bbedit commands:
bbdiff
bbedit
bbfind
I do not know very well all the path-config files and the real order they are read. I only know a few unix commands..
My current files in ~/ are:
~/.profile:
if [ -f ~/.bashrc ];
then
source ~/.bashrc
fi
~/bashrc:
. ~/bin/dotfiles/bashrc
then in . ~/bin/dotfiles/bashrc
. ~/bin/dotfiles/bash/env
. ~/bin/dotfiles/bash/config
. ~/bin/dotfiles/bash/aliases
and in . ~/bin/dotfiles/bash/env:
export PATH=/usr/local/bin:/opt/local/bin:/opt/local/sbin:$PATH
. ~/bin/dotfiles/bash/config is just empty
and . ~/bin/dotfiles/bash/aliases contains some alias commad.
Anyway, it SHOULD have read ~/bin/dotfiles/bash/env, but it doesn't. Or it reads it only after /etc/paths
~/.bash_profile is read first instead.
My current /etc/paths content:
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
Can anyone explain me the these mechanics? :P Or Maybe I should post this question to some Unix group?
When you type any command on a *NIX shell, the shell tries to resolve that command using the $PATH. Say your path is /usr/bin:/usr/local/bin, then this happens:
$ foo
- Does /usr/bin/foo exist? No.
- Does /usr/local/bin/foo exist? No.
- Does foo exist in the current working directory?
In other words, it looks at each $PATH element in turn and tries to find the executable you asked for there. This is the reason the typical configure-make-make install procedure starts with a ./configure, to make explicit that you want to run the configure executable in the current directory, not some system-wide command.
To figure out which foo it's actually choosing in the end, run:
$ which foo
You can run any command explicitly by providing its full path:
$ /usr/local/bin/foo # overrides /usr/bin/foo, should it exist
The export PATH=...:$PATH directive in your initialization scripts is simply prepending certain paths to your path, allowing you to override the precedence in which order commands are resolved. It's not ideal that /usr/local/bin is in there twice, but it's not really a problem either. You should take care not to let your path grow too long, since that may result in a lot of lookups for every command and may screw with your head, too.
See this for a comprehensive walkthrough of bash config files' loading order.

How to modify PATH for Homebrew?

Trying to install ruby 1.9.3, read that I need to install homebrew first. Ran brew doctor, and it's giving me a bunch of warnings. One of which is:
Warning: /usr/bin occurs before /usr/local/bin This means that
system-provided programs will be used instead of those provided by
Homebrew. The following tools exist at both paths:
easy_install
easy_install-2.6
Consider amending your PATH so that /usr/local/bin is ahead of
/usr/bin in your PATH.
How does one do what it's asking here?
open your /etc/paths file, put /usr/local/bin on top of /usr/bin
$ sudo vi /etc/paths
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
and Restart the terminal, #mmel
There are many ways to update your path. Jun1st answer works great. Another method is to augment your .bash_profile to have:
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
The line above places /usr/local/bin and /usr/local/sbin in front of your $PATH. Once you source your .bash_profile or start a new terminal you can verify your path by echo'ing it out.
$ echo $PATH
/usr/local/bin:/usr/local/sbin:/Users/<your account>/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Once satisfied with the result running $ brew doctor again should no longer produce your error.
This blog post helped me out in resolving issues I ran into. http://moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/
Just run the following line in your favorite terminal application:
echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile
Restart your terminal and run
brew doctor
the issue should be resolved
open bash profile in textEdit
open -e .bash_profile
Edit file or paste in front of PATH
export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:~/bin
save & close the file
*To open .bash_profile directly open textEdit > file > recent
To avoid unnecessary duplication, I added the following to my ~/.bash_profile
case ":$PATH:" in
*:/usr/local/bin:*) ;; # do nothing if $PATH already contains /usr/local/bin
*) PATH=/usr/local/bin:$PATH ;; # in every other case, add it to the front
esac
Credit: https://superuser.com/a/580611

Resources