今天在安装 Homebrew 的时候遇到一些小插曲特此记录一下~

执行 Homebrew 官网提供的安装语句的时候

1
LBinindeMacBook-Pro:~ abc1$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

出现以下提示信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown abc1 /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
HEAD is now at 02f0189 Merge pull request #2483 from MikeMcQuaid/audit-no-devel-version-alias
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/abc1/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
Warning: /usr/local/bin is not in your PATH.
==> Installation successful!
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
http://docs.brew.sh/Analytics.html
==> Next steps:
- Run `brew help` to get started
- Further documentation:
http://docs.brew.sh

接着我按照倒数第三行执行 brew help 命令

1
2
LBinindeMacBook-Pro:~ abc1$ brew help
-bash: brew: command not found

提示我 command not found ,肯定是没有安装好。

这时候注意到上面

这里写图片描述

有一行Warning

1
Warning: /usr/local/bin is not in your PATH.

提示我目录 /usr/local/bin 没有在PATH这个环境变量里。


小插曲

我查了资料 http://jingyan.baidu.com/article/d2b1d1029c1ea65c7e37d4c9.html ,按照上面的步骤做了之后,发现任何的命令都执行不了,ls -l 都无法执行!

后来 Mac的控制台命令无法使用command not found 按照这篇博客

1
2
3
4
export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin
cd ~/
touch .bash_profile
open .bash_profile

这样就打开了一个记事本,会显示你之前配置过的path,修改记事本或者不修改(建议可以把配置环境变量的语句写在里面)

此时输入更新命令

1
source .bash_profile

发现命令行又好啦~


正确添加环境变量的方法:

借鉴 Mac 可设置环境变量的位置、查看和添加PATH环境变量

用下面方法添加路径到PATH变量中

1
LBinindeMacBook-Pro:~ abc1$ export PATH=/usr/local/bin:$PATH

然后用echo查看

1
LBinindeMacBook-Pro:~ abc1$ echo $PATH

就添加成功了~

再执行Homebrew安装命令

1
LBinindeMacBook-Pro:~ abc1$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

此时已经没有Warning~

并且 brew help 也出现了帮助手册

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
LBinindeMacBook-Pro:~ abc1$ brew help
Example usage:
brew search [TEXT|/REGEX/]
brew (info|home|options) [FORMULA...]
brew install FORMULA...
brew update
brew upgrade [FORMULA...]
brew uninstall FORMULA...
brew list [FORMULA...]
Troubleshooting:
brew config
brew doctor
brew install -vd FORMULA
Developers:
brew create [URL [--no-fetch]]
brew edit [FORMULA...]
http://docs.brew.sh/Formula-Cookbook.html
Further help:
man brew
brew help [COMMAND]
brew home

至此,PATH环境变量配置以及Homebrew安装都已成功。

虽然有些低级错误,不过写下来牢记于心。