NVM on a Raspberry Pi 4 64-bit
So yesterday I got the new Raspberry Pi 4 8GB. I have been trying not to buy too much during COVID-19 outbreak, but an 8GB SBC has some allure, even if I am fully aware how limited these devices are in compute terms, it can be nice to have experience outside of Macbook / x86 Linux.
All My Raspberry Pi 4 devices are now running 64-bit kernel Raspbian.
On an x86 PC, you are often told, you need a 64-bit kernel to use more than 4GB RAM. While mostly true, it is certainly not true of the Raspberry Pi hardware, which seems to be able to access all 8GB with the stock Kernel and no edits. I am unsure how that is working, but It's nice to play with new things anyway.
The free -h command helps me to know how much RAM the system knows about.
This does not report 8GB, because the Raspberry Pi shares some System RAM with the VideoCore Graphics chip.
sudo rpi_update echo "arm_64bit=1" > /boot/config.txt
The above code-snippet is the fast-track to being able to run 64-bit using a Raspberry Pi 4.
Why switching language runtimes can be of benefit
In private organisations, often most applications will run within a single runtime. When you upgrade, everything moves forward, with no thought to backwards compatibility. While a useful trade-off saving time and money, this only works if you are not giving source access, or have an enormous degree of control over those using your software.
Being able to run multiple language runtimes somewhere, allows you some benefits:
- Ability to test upcoming versions.
- Ability to replicate client environments to troubleshoot.
- Quite often, the ability to run multiple configurations.
This is not without challenges, and it may not be right for all, but it is one technique in my toolbox.
The Raspberry pi device comes with nodeJS version 10 installed via Debian. I do not want to be limited to this version, and to be honest, I also do not want any NodeJS programs I have not installed running by default. I believe Node-RED is the application requiring NodeJS, but as I will setup a default NodeJS, this should not interfere. I Remove the built-in NodeJS using this command.
sudo apt remove --purge npm node-* nodejs-* libnode-dev libnode64
Once this was done, I downloaded NVM via the Git install method.
git clone https://github.com/nvm-sh/nvm.git .nvm cd ~/.nvm && git checkout v0.35.3 && cd .. export NVM_DIR="$HOME/.nvm" . "$NVM_DIR/nvm.sh" . "$NVM_DIR/bash_completion"
This takes a copy of the source, checks out a hopefully stable release, and then ensures I can use the nvm tool.
I then install from source. I did try this without the
-s flag, but it seemed to be problematic as it gave me an error message about node not existing.
env: node: No such file or directory
nvm install -s --lts nvm alias default v12.17.0 nvm use default node --version npm --version
The above took over an hour to complete, so if you are not as obsessed with being able to change NodeJS runtime versions as I am, that is fine.
Once this was completed, I was able to run NodeJS and npm without issue. Because I opted for a user-account version of nvm, which is the default, I should not have issues with permissions or needing to run sudo and risk the rest of my machine.