2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HomebrewでupgradeしたらError: An unexpected error occurred during the `brew link` stepとなった時の対応方法

Posted at

環境
OS : macOS Hight Sierra Virsion 10.13.1
Homebrew : 1年ぐらい使っていなかった

事象 : brew upgradeしたら怒られた

$ brew upgrade
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 5 taps (homebrew/apache, homebrew/science, homebrew/core, homebrew/php, caskroom/cask).
==> New Formulae
abyss                                haste-client                         homebrew/php/php72-phalcon           metis

<超長いので省略>

==> Upgrading ruby 
==> Downloading https://homebrew.bintray.com/bottles/ruby-2.4.2_1.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring ruby-2.4.2_1.high_sierra.bottle.tar.gz
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/lib/ruby/gems/2.4.0/doc/rubygems-2.6.14
Error: Permission denied @ dir_s_mkdir - /usr/local/lib/ruby/gems/2.4.0/doc/rubygems-2.6.14

原因 : /usr/localのPermissionがdeniedだから

doctorに聞いてみる
$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  ruby

Warning: Some installed formula are missing dependencies.
You should `brew install` the missing dependencies:
  brew install libtool

Run `brew missing` for more details.
doctorに言われたとおりにしてみる
$ sudo brew link ruby
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
なんか怖いこと言ってる気がするのでエラーに立ち戻る
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/lib/ruby/gems/2.4.0/doc/rubygems-2.6.14
Error: Permission denied @ dir_s_mkdir - /usr/local/lib/ruby/gems/2.4.0/doc/rubygems-2.6.14

Permissionがdeniedって言われているのに気がつく

対応方法 : /usr/localのPermissionをdeniedじゃなくす

Permissionをdeniedじゃなくす
$ sudo chown -R $(whoami) /usr/local
再度アップグレードするとできる
$ brew upgrade
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
elasticsearch@5.6
==> Updated Formulae
elasticsearch

==> Upgrading 9 outdated packages, with result:
gmp 6.1.2_1, wget 1.19.2, libpng 1.6.34, freetype 2.8.1, mpfr 3.1.6, glassfish 5.0, homebrew/php/php56 5.6.32_8, gcc 7.2.0, automake 1.15.1
==> Upgrading automake 
==> Downloading https://homebrew.bintray.com/bottles/automake-1.15.1.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring automake-1.15.1.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/automake/1.15.1: 131 files, 3.0MB

<超長いので省略>

==> Upgrading gcc 
Warning: Building gcc from source:
  The bottle needs the Xcode CLT to be installed.
==> Downloading https://ftp.gnu.org/gnu/gcc/gcc-7.2.0/gcc-7.2.0.tar.xz
######################################################################## 100.0%^[[1;2C
==> Downloading https://raw.githubusercontent.com/Homebrew/formula-patches/e9e0ee09389a54cc4c8fe1c24ebca3cd765ed0ba/gcc/6.1.0-jit.patch
######################################################################## 100.0%
==> Downloading https://raw.githubusercontent.com/Homebrew/formula-patches/df0465c02a/gcc/apfs.patch
######################################################################## 100.0%
==> Patching
==> Applying 6.1.0-jit.patch
patching file gcc/jit/Make-lang.in
==> Applying apfs.patch
patching file libstdc++-v3/include/Makefile.in
==> ../configure --build=x86_64-apple-darwin17.2.0 --prefix=/usr/local/Cellar/gcc/7.2.0 --libdir=/usr/local/Cellar/gcc/7.2.0/lib/gcc/7 --enable-
==> make
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?