Raspi setup nodejs 18 64bit
nguyennamdsn | March 16, 2023, 6:53 a.m.
Step 1: Update and Upgrade Your System
Since you will compile the source code o your system, you need to ensure that you are running the latest packages to avoid errors. Execute the command below on your Raspberry Pi.
sudo apt update
sudo apt upgrade
The upgrade command can take quite some time to finish depending on your internet connection and when you last upgraded your Pi.
Step 2: Check the Node Version You Need to Download
As said earlier, this method can only be used on specific Pi boards architecture depending on the node source code available. To know the architecture on which your PI is running on, execute the command below.
uname -m
From the image above, you can see we are running on armv8. This architecture version will guide us in downloading the required ode source code as described in the next step.
Step 3: Download NodeJS
Open your browser and navigate to the NodeJS Download Page. You will see the available binaries for different platforms and architecture, including Windows, Linux, macOS, x64, and ARM. We need to download the ARM binaries. Now you need to download the specific binary for your architecture. In our case, we are running armv8. Therefore, we will download NodeJS binaries for ARMv8.
Instead of clicking the download link and downloading the package using our browser or download manager, we will use the wget command. Right-click on the download links and select the option "copy link address" or "copy file location." Launch the Terminal on your Pi and use the syntax below to download the package.
sudo wget https://nodejs.org/dist/v18.15.0/node-v18.15.0-linux-arm64.tar.xz
When done, run the ls command, and you should see a node package.
Step 4: Extract the File
The package downloads in a compressed format; to extract it, use the syntax below.
sudo tar -xvf [file-name]
e.g
sudo tar -xvf node-v18.15.0-linux-arm64.tar.xz
When you rerun the ls command, you will now see a node directory.
Step 5: Copy the Extracted Files to Directory Path
To make Node available system-wide for the currently logged-in user, we need to copy the extracted file to the /usr/local directory. To get started, first navigate to the newly created directory using the cd command as shown below.
cd node-v18.15.0-linux-arm64
We will use the command below to copy all the contents to the /usr/local directory.
sudo cp -R * /usr/local
Let's discuss the command above in detail:
- -R: This parameter means that "copy all the files recursively." That enables us to copy a directory and all its contents.
- *: This asterisk means that we are copying everything in our current directory.
That's it! We have successfully installed NodeJS and NPM on our system.
Step 6: Verify Installation
When done, verify NodeJS and NPM installation by running the version command below.
node -- version
npm --version