LoginSignup
0
0

More than 1 year has passed since last update.

npmコマンドでのインストール時エラー対処法

Posted at

Angularの学習を始めるぞ!と思い、Angularをインストールしようと思ったら以下のエラーが。。。

homyu@homyunoAir udemy % npm install -g @angular/cli@14
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/@angular
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@angular'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@angular'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/@angular'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

めちゃくちゃ焦って調べたら、どうやら、node.jsを公式からパッケージでインストールしていたことが問題だったらしく、nodeのバージョン管理ツールが有効とのこと。

とりあえず、今回はnodebrewを使用することにしました。

homebrewをインストール

まずは、nodebrewのインストール前にhomebrewのインストールが必要なため、以下コマンドで実行。
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
※macの場合、パスを通す必要があるので、以下も実行。
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)"

nodebrewをインストール

そして、ようやく、nodebrewを以下コマンドでインストール。
brew install nodebrew
ちゃんとインストールできているか確認します。
nodebrew
以下のようにバージョン情報が出たらOKです!

nodebrew 1.2.0

Usage:
    nodebrew help                         Show this message
    nodebrew install <version>            Download and install <version> (from binary)
    nodebrew compile <version>            Download and install <version> (from source)
    nodebrew install-binary <version>     Alias of `install` (For backward compatibility)
    nodebrew uninstall <version>          Uninstall <version>
    nodebrew use <version>                Use <version>
    nodebrew list                         List installed versions
    nodebrew ls                           Alias for `list`
    nodebrew ls-remote                    List remote versions
    nodebrew ls-all                       List remote and installed versions
    nodebrew alias <key> <value>          Set alias
    nodebrew unalias <key>                Remove alias
    nodebrew clean <version> | all        Remove source file
    nodebrew selfupdate                   Update nodebrew
    nodebrew migrate-package <version>    Install global NPM packages contained in <version> to current version
    nodebrew exec <version> -- <command>  Execute <command> using specified <version>
    nodebrew prune [--dry-run]            Uninstall old versions, keeping the latest version for each major version

Example:
    # install
    nodebrew install v8.9.4

    # use a specific version number
    nodebrew use v8.9.4

nodebrewのセットアップ

以下コマンドで、nodebrewのセットアップをします。
nodebrew setup

次に、nodebrew経由でNode.jsをインストールします。
安定版が無難なので、バージョンにはstableを使用します。
nodebrew install-binary stable

次に、以下コマンドでインストールしたNode.jsを有効にします。
nodebrew use stable

次に、nodebrewにアクセスできるようPATHを通します。
echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
これでNode.jsが使えるようになりました!

最後に、nodeコマンドを実行してバージョン確認をしてみます。
node -v

以下のように安定版のバージョンが表示されれば完了です!

v18.13.0

Angularのインストール

やっと本題のAngularインストール!
果たしてうまくいくのか。。。
以下コマンドを実行!
npm install -g @angular/cli@14
※今回はAngular14を使用したかったため、バージョン指定しています。

インストール後、以下コマンドで確認!
ng --version

    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 14.2.10
Node: 18.13.0 (Unsupported)
Package Manager: npm 8.19.3 
OS: darwin arm64

Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1402.10 (cli-only)
@angular-devkit/core         14.2.10 (cli-only)
@angular-devkit/schematics   14.2.10 (cli-only)
@schematics/angular          14.2.10 (cli-only)

無事にインストールできました!👏

環境構築って大変ですよね。。。

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