0
0

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 1 year has passed since last update.

nodebrewからnodenvに移行しようとしてハマりまくった環境構築メモ

Last updated at Posted at 2021-12-02

概要

勉強したい本の環境構築が nodenv を利用していて、nodebrew を使っていたのですが揃えた方がきっと詰まらず進むだろうと思い環境切り替えを試みたら辛かった覚書です。

環境は相当長く使っている Mac で、Node を直接インストールしたのち、nodebrew に移行しています。
OS は現在は Catalina までアップデート済みです。

こちらを参考にさせていただいて切り替えていきます。
nodebrew から nodenv に移行しました

nodebrew アンインストール

現在のインストールバージョンをメモします。

% nodebrew list
v9.1.0

早速、最初の brew update でエラーでました。

% brew update
Error: /usr/local is not writable. You should change the ownership
and permissions of /usr/local back to your user account:
  sudo chown -R $(whoami) /usr/local

言われた通りコマンド叩きます。

% sudo chown -R $(whoami) /usr/local
chown: /usr/local: Operation not permitted

できない。

Homebrew 再インストールするらしいです。
参考:https://qiita.com/art_aco/items/834ebdf4abfb3445fc0c

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

今度こそ

% brew update
error: Not a valid ref: refs/remotes/origin/master

今度は違うエラー・・・。
しばらく待つとダウンロードが始まるけれど、結果エラーで終了。

fatal: ambiguous argument 'refs/remotes/origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
fatal: Needed a single revision
==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:0cb1cc7af109437fe0e020c9f3b7b95c3c709b140bde9f991ad2c1433496dd42
##################################################################################################################################### 100.0%
==> Pouring portable-ruby-2.6.8.yosemite.bottle.tar.gz
==> Homebrew has enabled anonymous aggregate formula and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics have been recorded yet (nor will be during this `brew` run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
Already up-to-date.
Error: Could not link:
/usr/local/etc/bash_completion.d/brew

Please delete these paths and run:
  brew update
Error: Could not link:
/usr/local/share/zsh/site-functions/_brew

Please delete these paths and run:
  brew update
Error: Could not link:
/usr/local/share/man/man1/brew.1

Please delete these paths and run:
  brew update
Error: Could not link:
/usr/local/share/doc/homebrew

Please delete these paths and run:
  brew update

書いてある通りに指摘のパスを消して再実行してみます。

% rm -rf /usr/local/etc/bash_completion.d/brew
% rm -rf /usr/local/share/zsh/site-functions/_brew
% rm -rf /usr/local/share/man/man1/brew.1
% rm -rf /usr/local/share/doc/homebrew
% brew update
fatal: Needed a single revision
Already up-to-date.

とりあえずできた?

やっと、nodebrewをアンインストールします。

% brew uninstall nodebrew
Warning: Unexpected method 'license' called on Cask alfred.
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
Warning: Unexpected method 'accessibility_access' called on Cask alfred.
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
Warning: Unexpected method 'license' called on Cask clipy.
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
Error: Cask 'clipy' definition is invalid: invalid 'depends_on macos' value: unknown or unsupported macOS version: :mavericks

はい、またエラー。mavericksとか懐かしい。
依存部分を削除します。

% /usr/bin/find "$(brew --prefix)/Caskroom/"*'/.metadata' -type f -name '*.rb' -print0 | /usr/bin/xargs -0 /usr/bin/perl -i -0pe 's/depends_on macos: \[.*?\]//gsm;s/depends_on macos: .*//g'

再挑戦。

% brew uninstall nodebrew
いろいろWarning
Uninstalling /usr/local/Cellar/nodebrew/0.9.6... (7 files, 36.8KB)

やっとアンインストールできた・・・。
まだ最初の参考サイトのコマンド3つ目までしか進んでない。

これもしておきます。

利用しているシェルの設定ファイルから以下を削除する。
export PATH=$HOME/.nodebrew/current/bin:$PATH

nodenv インストール

やっとnodenvインストール!
本ではanyenv経由でnodenvを入れているので、ここからは本の方に倣います。

ちなみに本ですと、これだけ実行すれば終わりだよ簡単!という感じでした。

$ brew install anyenv
$ echo 'eval "$(anyenv init -)"' >> ~/.zshrc
$ exec $SHELL -l
$ anyenv install nodenv
$ exec $SHELL -l

やってみます。

% brew install anyenv
fatal: Needed a single revision
Warning: No available formula with the name "anyenv".
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

簡単じゃない。
う、うーん。先生助けてください。

% brew doctor
Warning: Unexpected method 'license' called on Cask karabiner.
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
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 or file an issue; just ignore this. Thanks!

Warning: Homebrew/homebrew-core was not tapped properly! Run:
  rm -rf "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core"
  brew tap homebrew/core

Warning: Some installed kegs have no formulae!
This means they were either deleted or installed with `brew diy`.
You should find replacements for the following formulae:
  pkg-config
  libtiff
  libtool
  czmq
  libpng
  pixman
  gdbm
  freetype
  python
  pango
  icu4c
  zeromq
  harfbuzz
  glib
  readline
  cairo
  sqlite
  gobject-introspection
  fontconfig
  gettext
  libsodium
  pcre
  ricty
  jpeg
  zsh
  fontforge
  openssl
  git
  libffi

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  pkg-config
  libtiff
  libtool
  czmq
  libpng
  pixman
  gdbm
  freetype
  python
  pango
  icu4c
  zeromq
  harfbuzz
  glib
  readline
  cairo
  sqlite
  gobject-introspection
  fontconfig
  gettext
  libsodium
  pcre
  ricty
  jpeg
  zsh
  fontforge
  openssl
  git
  libffi
Error: No available formula with the name "git".

すごいでた。過去のいろいろが荒ぶっています。
1つ目からコマンド叩いていきます・・・。

% rm -rf "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core"
% brew tap homebrew/core

時間かかりますが完了。
再度先生にお願い。

% brew doctor
Warning: Some installed kegs have no formulae!
This means they were either deleted or installed with `brew diy`.
You should find replacements for the following formulae:
  ricty

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  pkg-config
  libtiff
  libtool
  czmq
  libpng
  pixman
  gdbm
  freetype
  python
  pango
  zeromq
  harfbuzz
  glib
  cairo
  gobject-introspection
  fontconfig
  gettext
  libsodium
  pcre
  ricty
  jpeg
  zsh
  fontforge
  git

Warning: An outdated version (2.9.2) of Git was detected in your PATH.
Git 2.14.3 or newer is required for Homebrew.
Please upgrade:
  brew upgrade git

Warning: Broken symlinks were found. Remove them with `brew cleanup`:
  /usr/local/bin/subl

Warning: Some installed formulae are missing dependencies.
You should `brew install` the missing dependencies:
  brew install ca-certificates fribidi giflib graphite2 libpthread-stubs libspiro libuninameslist libx11 libxau libxcb libxdmcp libxext libxrender lzo m4 mpdecimal ncurses openssl@1.1 pcre2 xorgproto xz

Run `brew missing` for more details.

2つ目だったエラー解消へ。さよなら ricty

% brew uninstall ricty

3つ目のリンクエラー解消へ。多い・・・。

% brew link pkg-config libtiff libtool 省略

4つ目。Git古すぎ問題。

% brew upgrade git
% git --version
git version 2.34.1

5つ目。お掃除。

% brew cleanup

6つ目。もういらないものも居そうですが。

% brew install ca-certificates fribidi giflib graphite2 libpthread-stubs libspiro libuninameslist libx11 libxau libxcb libxdmcp libxext libxrender lzo m4 mpdecimal ncurses openssl@1.1 pcre2 xorgproto xz

さて、これで先生も落ち着いてくれるかなと思ったら、

% brew doctor
zsh: killed     brew doctor

PC 再起動します。

% brew doctor
Your system is ready to brew.

やっときれいになりました!
インストールに戻ります。

% brew install anyenv

無事に完了。

2行目のコマンドの eval "$(anyenv init -)" は zsh 用ファイルを分けているので別ファイルに書きましたが、がエラー出ました。

ANYENV_DEFINITION_ROOT(/Users/*****/.config/anyenv/anyenv-install) doesn't exist. You can initialize it by:
> anyenv install --init

言われた通りにコマンドを実行します。

% anyenv install --init 
Manifest directory doesn't exist: /Users/*****/.config/anyenv/anyenv-install
Do you want to checkout https://github.com/anyenv/anyenv-install.git? [y/N]: y
Completed!

もう一度実行したら eval "$(anyenv init -)" のエラーは解消しました。

% anyenv install nodenv
% exec $SHELL -l
% nodenv install -l
0.1.14
0.1.15
0.1.16

やっと動きました・・・!!!

まとめ

本命の言語学習に入る前に力尽きそうでしたがなんとか終わりました。
環境構築はまっさらな状態からでないとハマりどころが多く・・・結局ほぼ全部のコマンドでエラーになったような気がします。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?