inmsg.cn

槑槑笔记

苹果mac电脑中brew的安装使用及卸载详细教程

2019-9-11 admin

brew 又叫Homebrew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件, 只需要一个命令, 非常方便

brew类似ubuntu系统下的apt-get的功能

安装brew

brew 的官方网站: http://brew.sh/在官方网站对brew的用法进行了详细的描述

安装方法: 在Mac中打开Termal: 输入命令:

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

image

不知道为什么, 在国内经常被屏蔽

使用brew安装软件

一个命令就搞定了, 比如安装git

brew install git

image

比如安装wget

brew install wget

使用brew卸载软件

卸载更方便了

brew uninstall wget

image

使用brew查询软件

有时候,你不知道你安装的软件的名字, 那么你需要先搜索下, 查到包的名字。

比如我要安装

brew search /wge*/

/wge*/是个正则表达式, 需要包含在/中

image

其他brew命令

brew list 列出已安装的软件

brew update 更新brew

brew home 用浏览器打开brew的官方网站

brew info 显示软件信息

brew deps 显示包依赖

image

brew upgrade 升级
升级完毕后,会有一个summary(总结) 及 Caveats(注意事项),如:

php5.6

==> php@5.6
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/5.6/

php@5.6 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have php@5.6 first in your PATH run: echo 'export PATH="/usr/local/opt/php@5.6/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@5.6/sbin:$PATH"' >> ~/.zshrc

For compilers to find php@5.6 you may need to set: export LDFLAGS="-L/usr/local/opt/php@5.6/lib" export CPPFLAGS="-I/usr/local/opt/php@5.6/include" To have launchd start php@5.6 now and restart at login:
  brew services start php@5.6
Or, if you don't want/need a background service you can just run:
  php-fpm 

php7.0

==> php@7.0
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/php@7.0/lib/httpd/modules/libphp7.so
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>
Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.0/

php@7.0 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have php@7.0 first in your PATH run:  //如 果需要在路径(命令行)中使用,请执行下面这条语句 echo 'export PATH="/usr/local/opt/php@7.0/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.0/sbin:$PATH"' >> ~/.zshrc

For compilers to find php@7.0 you may need to set: export LDFLAGS="-L/usr/local/opt/php@7.0/lib" export CPPFLAGS="-I/usr/local/opt/php@7.0/include" To have launchd start php@7.0 now and restart at login:
  brew services start php@7.0
Or, if you don't want/need a background service you can just run:
  php-fpm 

系统中正在使用的版本php7.2

==> php
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch> Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.2/

To have launchd start php now and restart at login:
  brew services start php Or, if you don't want/need a background service you can just run:
  php-fpm 

注意:
切换版本步骤:

  • 执行PHP切换命令,如下brew-php-switcher.
  • 修改apache的配置文件httpd.conf,即可在phpinfo()中,看到对应的PHP版本
  • 修改命令行下的PHP版本,执行对应版本的echo语句
    • echo 'export PATH="/usr/local/opt/php@7.0/bin:$PATH"' >> ~/.zshrc
    • echo 'export PATH="/usr/local/opt/php@7.0/sbin:$PATH"' >> ~/.zshrc
  • 重启服务器,如果不起作用,重启下电脑

mac下使用命令切换PHP版本,使用brew-php-switcher工具

brew-php-switcher 5.6 brew-php-switcher 7.0 brew-php-switcher 7.1 brew-php-switcher 7.2 

修改apache下的http.conf配置文件信息,以对应环境中的PHP版本

LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so #LoadModule php7_module /usr/local/opt/php@7.0/lib/httpd/modules/libphp7.so #LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so #LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so 

参考文档:http://www.jb51.net/os/MAC/101860.html

安装完成后的记录参考:主要有Extensions \ PHP CLI \ PHP-FPM

The php.ini file can be found in:

/usr/local/etc/php/7.2/php.ini

✩✩✩✩ Extensions ✩✩✩✩

If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:

PATH="/usr/local/bin:$PATH" PHP72 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP.

✩✩✩✩ PHP CLI ✩✩✩✩

If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file:

export PATH="$(brew --prefix homebrew/php/php72)/bin:$PATH"

✩✩✩✩ FPM ✩✩✩✩

To launch php-fpm on startup:

mkdir -p ~/Library/LaunchAgents

cp /usr/local/opt/php72/homebrew.mxcl.php72.plist ~/Library/LaunchAgents/

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php72.plist

The control script is located at /usr/local/opt/php72/sbin/php72-fpm

OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:

PATH="/usr/local/sbin:$PATH"

You may also need to edit the plist to use the correct "UserName".

Please note that the plist was called 'homebrew-php.josegonzalez.php72.plist' in old versions of this formula.

With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system you have to install php with the --with-httpd option. See  brew options php72 for more details.

To have launchd start homebrew/php/php72 now and restart at login:

brew services start homebrew/php/php72

==> Summary