LoginSignup
4
2

More than 5 years have passed since last update.

ARMv6機のRaspbian(Stretch)にnpmコマンドをインストール

Last updated at Posted at 2019-04-07

Raspberry Pi Zero W(ARMv6)のRaspbian(Stretch)にnodeコマンド、npmコマンド、npxコマンドをインストール

Raspbian(Stretch)(Debian(Stretch))ではnpmのパッケージが提供されなくなった。このため、デフォルトでインストールされるnodejsパッケージを一旦アンインストールして入れ直す必要がある。

NodeSource Node.js Binary Distributionsに記載されている通り、以下の手順でインストールしようとすると、

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

次のエラーが表示される。

## Installing the NodeSource Node.js 8.x LTS Carbon repo...


## You appear to be running on ARMv6 hardware. Unfortunately this is not currently supported by the NodeSource Linux distributions. Please use the 'linux-armv6l' binary tarballs available directly from nodejs.org for Node.js 4 and later.

Pi Zero WはARMv6を使用しているため、NodeSourceからパッケージが提供されていない。
ここでは、Pi Zeroシリーズ環境でnode.jsを稼働させる方法について記載する。

詳細やその他バージョンのインストール方法はNodeSource Node.js Binary Distributionsを確認すること。

  1. インストール済みのバージョンを確認する。

    $ node -v
    v8.11.1
    
    $ npm -v
    -bash: npm: command not found
    
  2. 一旦、nodejsパッケージをアンインストールする。

    $ sudo apt remove nodejs
    $ sudo apt autoremove
    
  3. https://nodejs.org/dist/latest/で最新版のバージョンを確認し、環境変数にセットする。

    $ VERSION=v11.13.0
    $ DISTRO=linux-armv6l
    
  4. How to install Node.js via binary archive on Linux?に従い、インストールする。

    $ cd /usr/src
    $ sudo wget https://nodejs.org/dist/latest/node-$VERSION-$DISTRO.tar.xz
    $ sudo mkdir -p /usr/local/lib/nodejs
    $ sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs
    
  5. .profileファイルを編集する。

    $ vi ~/.profile
    
    # Nodejs
    VERSION=v11.13.0
    DISTRO=linux-armv6l
    export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH
    
  6. .profileファイルを有効化する。

    $ . ~/.profile
    
  7. sudoリンクを作成する。

    $ sudo ln -s /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/node /usr/bin/node
    $ sudo ln -s /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/npm /usr/bin/npm
    $ sudo ln -s /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/npx /usr/bin/npx
    
  8. 新たにインストールされたバージョンを確認する。

    $ node -v
    v11.13.0
    $ npm -v
    6.7.0
    $ npx -v
    6.7.0
    
4
2
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
4
2