Raspberry Pi Zero の Node.js を最新バージョンに

ダウンロードと解凍

```

wget https://unofficial-builds.nodejs.org/download/release/v18.14.0/node-v18.14.0-linux-armv6l.tar.xz

tar xvfJ node-v18.14.0-linux-armv6l.tar.xz

```

インストールとリブート

```

sudo cp -R node-v18.14.0-linux-armv6l/* /usr/local

rm -rf node-*

sudo reboot

```

バージョンを確認

```

node -v && npm -v

```

非公式ビルド: https://unofficial-builds.nodejs.org/download/

参考: https://hassancorrigan.com/blog/install-nodejs-on-a-raspberry-pi-zero/

#NodeJS #RaspberryPi

Reply to this note

Please Login to reply.

Discussion

cron では、PATH に `/usr/local/bin` を追加する必要がある

例:

```

0 * * * * export PATH=/usr/local/bin/:$PATH; cd /home/pi/bin/vercel-nostr-posts && npm run deploy > /dev/null 2>&1

```

#NodeJS #RaspberryPi

うまくいかない例

```

0 * * * * cd /home/pi/bin/vercel-nostr-posts && npm run deploy > /dev/null 2>&1

```

`/usr/bin` の node と npm が使用されるため、うまくいかない

#NodeJS #RaspberryPi

`/usr/local/bin` からのフルパスで npm を記載

```

0 * * * * cd /home/pi/bin/vercel-nostr-posts && /usr/local/bin/npm run deploy > /dev/null 2>&1

```

以下のエラーが発生する

```

ERROR: npm v9.3.1 is known not to run on Node.js v12.22.12. You'll need to

upgrade to a newer Node.js version in order to use this version of npm. This

version of npm supports the following node versions: `^14.17.0 || ^16.13.0 ||

>=18.0.0`. You can find the latest version at https://nodejs.org/.

```

`/usr/bin` の node が使用されるため、うまくいかない

#NodeJS #RaspberryPi

PATH に `/usr/local/bin` を追加する

```

0 * * * * PATH=/usr/local/bin/:$PATH cd /home/pi/bin/vercel-nostr-posts && /usr/local/bin/npm run deploy > /dev/null 2>&1

```

エラーは変わらない

```

ERROR: npm v9.3.1 is known not to run on Node.js v12.22.12. You'll need to

upgrade to a newer Node.js version in order to use this version of npm. This

version of npm supports the following node versions: `^14.17.0 || ^16.13.0 ||

>=18.0.0`. You can find the latest version at https://nodejs.org/.

```

シェル変数 (`PATH=/usr/local/bin/:$PATH`) は子プロセスには受け渡されないため、うまくいかない

#NodeJS #RaspberryPi

64-bit

```

wget https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux-arm64.tar.xz

tar xvfJ node-v22.11.0-linux-arm64.tar.xz

sudo cp -R node-v22.11.0-linux-arm64/* /usr/local

rm -rf node-*

sudo reboot

```

#NodeJS #RaspberryPi