ChatGPT解决这个技术问题 Extra ChatGPT

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?

@AristotlePagaltzis's answer on SuperUser gives the best solution in my opinion, allowing your system apps to continue using /usr/bin, while you selectively symlink the Homebrew executables that you want to use instead of the Apple-shipped versions, such as Git.
@mrdavidjcole: fengd did not answered that question?
Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See What topics can I ask about here in the Help Center. Perhaps Super User or Apple Stack Exchange would be a better place to ask. Also see Where do I post questions about Dev Ops?.

f
fengd

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


Reload the environment or start a new terminal after making this change.
Disagree with this - should use the below answer - time machine etc will not pick this change up I think as outside user folder.
This is also the best solution I've found if your problem is that RVM and Homebrew both seem to be competing for same real estate in your .bash_profile file.
I would NOT edit /etc/paths; instead, use the .profile / .bash_profile methods described elsewhere (e.g., answer by @avelis below or for a more paranoid approach, see the first comment referencing AristotlePagaltzis answer on SuperUser.
You may want to try using the nano terminal text editor instead of via. I found this to be easier to use. "sudo nano /etc/paths" instead of "sudo vi /etc/paths".
a
avelis

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/


@JanuszChudzynski For Jun1st's solution, it might be that you have to restart the command line session in order to see the change.
Recent versions of homebrew day: Consider setting your PATH so that /usr/local/bin occurs before /usr/bin. Here is a one-liner: echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile. Which is basically what this answer suggests.
However I doubt it is the right way. See below: Before change:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin change: echo export PATH="/usr/local/bin:$PATH >> ~/.bash_profile After change: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin This means that if a command is not found in /usr/local/bin it might get searched twice before it is found in another path. I think it is better to change the /etc/paths file
$ echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile gives me $PATH"' >> ~/.bash_profile -bash: $: command not found
@rpeg I am sure if you web search for tutorials there is an abundance of resources, but here is one I know of. linux.com/learn/tutorials/272346-bash-101-working-at-the-cli
i
iceturk22

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


If you are using zsh use this command echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc
S
Siddhant Raut

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


C
Community

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