Cannot install nodejs in a container

I switched to Raspbian Lite on my Raspberry Pi 4 and found that I’m having issues installing nodejs in my containers. I’m using Debian containers

I have tried to install it both with NVM and from nodesource package.

NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm isntall stable

node /root/.nvm/versions/node/some-version/bin/node no such file or directory
but the file is there

Nodesource:
curl -sSL https://deb.nodesource.com/setup_14.x | sudo bash -
apt-get install -y nodejs

Package ‘nodejs’ has no installation candidate

Works fine on the host, I have tried a number of versions and both on Debian 10 and 11 containers.

here’s what’s working for me inside a container


curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

node --version
npm --version

Is this running on a raspbian host and is it a debian container? For me didn’t work, tried a lot of methods.

Switching my containers to Ubuntu, the problem doesn’t occur on an Ubuntu container.

Hi xiki,
I dont know which Raspberry pi you are using but eventually it is arm. I have been testing my arm cluster which is arm64 and installing just fine. Feel free to respond. Thanks.
Here are the steps.

root@debian:~# curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
-bash: curl: command not found
root@debian:~# apt update
Hit:1 http://deb.debian.org/debian bullseye InRelease
Hit:2 http://security.debian.org bullseye-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
root@debian:~# apt install curl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libbrotli1 libcurl4 libnghttp2-14 libpsl5 librtmp1 libssh2-1 publicsuffix
The following NEW packages will be installed:
  curl libbrotli1 libcurl4 libnghttp2-14 libpsl5 librtmp1 libssh2-1 publicsuffix
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,311 kB of archives.
After this operation, 2,982 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian bullseye/main arm64 libbrotli1 arm64 1.0.9-2+b2 [267 kB]
Get:2 http://deb.debian.org/debian bullseye/main arm64 libnghttp2-14 arm64 1.43.0-1 [73.8 kB]
Get:3 http://deb.debian.org/debian bullseye/main arm64 libpsl5 arm64 0.21.0-1.2 [57.1 kB]
Get:4 http://deb.debian.org/debian bullseye/main arm64 librtmp1 arm64 2.4+20151223.gitfa8646d.1-2+b2 [59.4 kB]
Get:5 http://deb.debian.org/debian bullseye/main arm64 libssh2-1 arm64 1.9.0-2 [150 kB]
Get:6 http://deb.debian.org/debian bullseye/main arm64 libcurl4 arm64 7.74.0-1.3+b1 [321 kB]
Get:7 http://deb.debian.org/debian bullseye/main arm64 curl arm64 7.74.0-1.3+b1 [261 kB]
Get:8 http://deb.debian.org/debian bullseye/main arm64 publicsuffix all 20210108.1309-1 [121 kB]
Fetched 1,311 kB in 1s (1,134 kB/s) 
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libbrotli1:arm64.
(Reading database ... 14649 files and directories currently installed.)
Preparing to unpack .../0-libbrotli1_1.0.9-2+b2_arm64.deb ...
Unpacking libbrotli1:arm64 (1.0.9-2+b2) ...
Selecting previously unselected package libnghttp2-14:arm64.
Preparing to unpack .../1-libnghttp2-14_1.43.0-1_arm64.deb ...
Unpacking libnghttp2-14:arm64 (1.43.0-1) ...
Selecting previously unselected package libpsl5:arm64.
Preparing to unpack .../2-libpsl5_0.21.0-1.2_arm64.deb ...
Unpacking libpsl5:arm64 (0.21.0-1.2) ...
Selecting previously unselected package librtmp1:arm64.
Preparing to unpack .../3-librtmp1_2.4+20151223.gitfa8646d.1-2+b2_arm64.deb ...
Unpacking librtmp1:arm64 (2.4+20151223.gitfa8646d.1-2+b2) ...
Selecting previously unselected package libssh2-1:arm64.
Preparing to unpack .../4-libssh2-1_1.9.0-2_arm64.deb ...
Unpacking libssh2-1:arm64 (1.9.0-2) ...
Selecting previously unselected package libcurl4:arm64.
Preparing to unpack .../5-libcurl4_7.74.0-1.3+b1_arm64.deb ...
Unpacking libcurl4:arm64 (7.74.0-1.3+b1) ...
Selecting previously unselected package curl.
Preparing to unpack .../6-curl_7.74.0-1.3+b1_arm64.deb ...
Unpacking curl (7.74.0-1.3+b1) ...
Selecting previously unselected package publicsuffix.
Preparing to unpack .../7-publicsuffix_20210108.1309-1_all.deb ...
Unpacking publicsuffix (20210108.1309-1) ...
Setting up libpsl5:arm64 (0.21.0-1.2) ...
Setting up libbrotli1:arm64 (1.0.9-2+b2) ...
Setting up libnghttp2-14:arm64 (1.43.0-1) ...
Setting up librtmp1:arm64 (2.4+20151223.gitfa8646d.1-2+b2) ...
Setting up libssh2-1:arm64 (1.9.0-2) ...
Setting up publicsuffix (20210108.1309-1) ...
Setting up libcurl4:arm64 (7.74.0-1.3+b1) ...
Setting up curl (7.74.0-1.3+b1) ...
Processing triggers for libc-bin (2.31-13) ...
root@debian:~# curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -

## Installing the NodeSource Node.js 16.x repo...


## Populating apt-get cache...

+ apt-get update
Hit:1 http://security.debian.org bullseye-security InRelease
Hit:2 http://deb.debian.org/debian bullseye InRelease
Reading package lists... Done

## Confirming "bullseye" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_16.x/dists/bullseye/Release'

## Adding the NodeSource signing key to your keyring...

+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null

## Creating apt sources list file for the NodeSource Node.js 16.x repo...

+ echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x bullseye main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x bullseye main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
Hit:1 http://security.debian.org bullseye-security InRelease
Hit:2 http://deb.debian.org/debian bullseye InRelease                   
Get:3 https://deb.nodesource.com/node_16.x bullseye InRelease [4,586 B] 
Get:4 https://deb.nodesource.com/node_16.x bullseye/main arm64 Packages [768 B]
Fetched 5,354 B in 3s (1,988 B/s)
Reading package lists... Done

## Run `sudo apt-get install -y nodejs` to install Node.js 16.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
     echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn


root@debian:~# apt-get install -y nodejs
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 25.5 MB of archives.
After this operation, 121 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_16.x bullseye/main arm64 nodejs arm64 16.8.0-deb-1nodesource1 [25.5 MB]
Fetched 25.5 MB in 9s (2,726 kB/s)                                                                                                                                                                                                       
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package nodejs.
(Reading database ... 14716 files and directories currently installed.)
Preparing to unpack .../nodejs_16.8.0-deb-1nodesource1_arm64.deb ...
Unpacking nodejs (16.8.0-deb-1nodesource1) ...
Setting up nodejs (16.8.0-deb-1nodesource1) ...
root@debian:~# node --version
v16.8.0
root@debian:~# npm --version
7.21.0
1 Like

Hi cemzafer, thank you for the console. With the same method I get nodejs has no installation candidate. I also noticed that my output for the curl command includes the following line just after Reading package lists... Done

N: Skipping acquire of configured file 'main/binary-armel/Packages' as repository 'https://deb.nodesource.com/node_16.x bullseye InRelease' doesn't support architecture 'armel'

My PI: Raspberry Pi 4 Model B Rev 1.4r

What is your debian container version?

Tried both Debian 10 and 11 with same result.

So I’m doing lxc launch images:debian/11 (or 10)

Can you try with this?

lxc launch images:debian/11/cloud test

It worked!!! Thank you so much cemzafer! :pray: :pray: :pray:

You are welcome. :+1: