新买的macbook pro bash版本为3.2.57,需要升级才能支持关联数组
升级主要涉及到 SIP(系统完整性保护)的关闭,brew的下载,以及进行bash替换和之后出现的无法开机的问题
这个比较简单,重新启动之后按住 command + R
键之后,进入修复模式,然后找到 实用工具 -> 终端 ,输入 csrutil status
查看到开启状态,输入csrutil disable
就可以将SIP关闭,然后输入 reboot 重启启动即可,重启之后如果报read-only file system, 需要执行
$ sudo mount -uw /
来重新挂载磁盘
家里网不怎么好,可以先获取下载的脚本,然后修改源
$ cd ~
$ curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
brew_install文件如下
#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere (which is
# unsupported) you can untar https://github.com/Homebrew/brew/tarball/master
# anywhere you like.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
修改BREW_REPO为
BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze
这是清华的镜像源
之后运行
$ /usr/bin/ruby ~/brew_install
进行安装
我在安装到
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core‘...
的时候会卡住,之后报错
fatal: unable to access ‘https://github.com/Homebrew/homebrew-core/‘: LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
我们需要手动建文件夹以及克隆库
$ cd "${brew --repo}"
$ cd Library/Taps/
$ mkdir -p homebrew/homebrew-core
$ mkdir homebrew/homebrew-core
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
之后输入
brew update
后进行更新
最后设置一下bintray镜像即可
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
$ brew install bash
验证安装结果,系统中并存两个版本
$ which -a bash
/usr/local/bin/bash
/bin/bash
在PATH环境变量中,新版本(/usr/local/bin)的目录优先于旧版本(/bin)
$ echo $PATH
/Users/ielgnahz/Documents/scala/bin:/Users/ielgnahz/Documents/maven/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
所以现在再检测bash版本时就显示为新版
$ bash --version
GNU bash,版本 5.0.16(1)-release (x86_64-apple-darwin19.3.0)
Copyright (C) 2019 Free Software Foundation, Inc.
许可证 GPLv3+: GNU GPL 许可证第三版或者更新版本 <http://gnu.org/licenses/gpl.html>
本软件是自由软件,您可以自由地更改和重新发布。
在法律许可的情况下特此明示,本软件不提供任何担保。
我一般习惯使用sh命令执行脚本,但sh命令还是3.2版本的,需要在/usr/local/bin目录下创建一个
$ sudo cp /usr/local/bin/bash /usr/local/bin/sh
一开始我是按照网上的办法将SIP关闭后,将旧版本的bash做了备份,然后直接使用新版本的bash替换旧版本的bash,即
$ sudo mount -uw / #重新挂载磁盘,否则会报read-only file system
$ sudo mv /bin/bash /bin/bash.origin
$ sudo ln -s /usr/local/opt/bash/bin/bash /bin/bash
之后启动SIP后会出现重新启动后卡在读进度条这个页面的问题,将SIP关闭之后不卡在读进度条的页面了,可能原因就是修改了/bin/bash的原因,所以我就采用了两个bash并存的办法。
即 将备份的bash恢复到/bin/bash后再开启SIP就不会卡在读进度条页面。
参考:
https://www.cnblogs.com/beyondmch/articles/8331478.html
https://www.jianshu.com/p/905d178f433c
原文:https://www.cnblogs.com/ielgnahz/p/12323563.html