Install Nodejs On Alpine

Alpine Linux, unlike mainstream/traditional Linux distributions, is based on BusyBox, a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions - musl. There currently is no musl based binary published in the nodejs official builds but they do publish a musl based binary in the nodejs unofficial builds which they use in the node:alpine docker image. The node:alpine docker image is a potential alternative to nvm for using node on alpine linux.

Package details. Package: nodejs-current: Version: 16.9.0-r0: Description: JavaScript runtime built on V8 engine - current stable version. For the recent versions of Alpine (v3.8+) the correct way to install nodejs with npm is: apk add -update nodejs npm. However, npm package depends on nodejs, so you can do: apk add -update npm. Note: since Alpine 3.8 there is no nodejs-npm package.

Alpine

For now you can override the nvm_get_arch function to return x64-musl on x64 Alpine Distributions. Currently the Node project only has unofficial builds for x64-musl. Sorry no ARM-musl/x86-musl,etc builds for now. The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Official Alpine-compatible binaries.

For more info about unofficial builds visit: https://unofficial-builds.nodejs.org/

If installing nvm on Alpine Linux is still what you want or need to do, you should be able to achieve this by running one of the following from your Alpine Linux shell:

Using Precompiled Binaries on Alpine

Pre-compiled binaries for musl based architectures are unofficially available for most node versions after node v8.16.0

  • libstdc++ - is the only package that is necessary to run node/npm once it is installed.
  • bash - is required to install nvm... BusyBox's sh has some issues with chmoding the nvm-exec file, but bash can be removed again after install if you want to slim your image.
  • coreutils/curl - is required to for nvm because BusyBox is not 100% POSIX compliant. Mainly ls not accepting a -q argument and wget not having the progress bar option.

Since there are no io.js builds available for musl you can also disable all io.js versions from showing up in nvm ls-remote by also running:

Building from Source on Alpine

There is a -s flag for nvm install which requests nvm download Node source and compile it locally. This does not use anything unofficial but it is much slower and more cpu intensive to install and build each version of node.

Similar to the pre-compiled binaries

  • libstdc++ - is the only package that is necessary to run node/npm once it is installed.

A useful tool to help with diagnosing network related issues on Azure App Service is TcpPing. Below are the steps for installing the tool for Debian and Alpine based Docker images.

Prerequisites

Install Nodejs On Alpine Pro

  • Your Web App must be running
  • If using a custom container, SSH access must be configured.

Installation - Debian

Nodejs
  1. Go to your Kudu site (i.e https://<sitename>.scm.azurewebsites.net/webssh/host) to SSH into your app.
  2. apt-get install tcptraceroute
  3. cd /usr/bin
  4. wget http://www.vdberg.org/~richard/tcpping
  5. chmod 755 tcpping
  6. apt install bc

Sample WebSSH Session

Installation - Alpine

  1. Go to your Kudu site (i.e https://<sitename>.scm.azurewebsites.net/webssh/host) to SSH into your app.
  2. apk update
  3. apk add tcptraceroute
  4. cd /usr/bin
  5. wget http://www.vdberg.org/~richard/tcpping
  6. chmod 755 tcpping
  7. If you receive an error “cannot find bc. Install bc package:” use, apt install bc

Sample WebSSH Session

Install Nodejs On Alpine

Install Nodejs On Alpine Street

TIP

Install Nodejs On Alpine

In certain scenarios where the WebApp/container is unable to start or SSH is not configured in the Custom Docker Image, you could use tcpping tool from the Kudu Container. The Kudu container is used for build purpose and has tcpping pre-installed. You can SSH into the Kudu Container via: https://[webappname].scm.azurewebsites.net/newui/kududebug