Environment (May 2023): Ubuntu 22.04, nvm v0.39.3, NodeJS v18.16.0, npm@5.9.1
That time of the month again! Another installation script to standardize stuff. Approach is similar to that used in installing Python and Ruby, i.e. a NodeJS version manager to manage different versions of NodeJS. Adapted from DigitalOcean's article, which goes into more detail if need be.
Install the latest nvm (Node Version Manager) version using their installer script, the one below is for v0.39.3. Update procedure is the same as the installation procedure.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash exec $SHELL
List the versions available for installation, and then install the desired version (either by specifying version, or using an alias). Alternatively, the latest LTS version can be automatically selected using nvm install --lts
and nvm use --lts
.
nvm list-remote nvm install lts/hydrogen nvm use lts/hydrogen
See the following instructions for starting nodejs apps via systemd when using nvm, in the following gist. But in short, need to make the service script run a bash script that first sources the nvm shims, then runs the desired command:
#!/bin/bash source /home/justin/.nvm/nvm.sh ...<npm app here>...
[Unit] Description=... [Service] User=... Group=... Type=simple WorkingDirectory=... ExecStart=/path/to/start.sh [Install] WantedBy=multi-user.target