There are more and more arm64 CPUs(Central Processing Unit) on the market in different hardware configurations able to run Ubuntu Linux and to run serious processing tasks. Even some cloud services providers included arm64 processors to their offer. One of the biggest names in the cloud industry, Oracle, offers interesting always free virtual machine instances based on Ampere Arm chip. With these virtual machines, besides Always free plan, you get better scaling performance meaning more controlled price performance ratio than with x86 architecture CPUs. It’s also nice to know that cloud company won’t bill your credit card unless you explicitly change your pricing plan which is not the always the case in the cloud industry. Installing Puppeteer on arm64 processors is still bit more complicated than on x86 CPUs, so to make it as straight forward as possible read on.
First off, Ubuntu is go to Linux distribution for this task as the best supported distribution from community. You always want to start some new task with the best supported Linux and once you setup everything to work as you planned you can try other more specialized distributions. For example, OCI (Oracle Cloud Infrastructure) offers Oracle Linux as default option for operating system but when it comes to installing Node JS and especially Puppeteer on arm64 architecture CPU it’s not the one you want to select. Installing Node JS is not a big issue even it’s not straight forward but installing Puppeteer is real pain if not still impossible. The real issue behind is problem of installation of Chrome or Chromium on arm64 so you have to be prepared to compile source code and what not.
With Ubuntu the situation is bit better because open source community around Ubuntu is bigger and many less known problems are already being solved, so you don’t need to spend additional time troubleshooting. Let’s get started.
First, we are going to install Node JS. There are few options to install Node JS on your operating system, in this case Ubuntu. The one that will work on the most distributions and also the most flexible one is using NVM (Node Version Manager). With NVM you can easily install or update multiple versions of Node JS or make a clean switch between versions without paying attention on multiple binaries, etc. To install NVM type this in command line:
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
and finally:
# source ~/.profile
Now that we have NVM installed type:
# nvm install 17
to install specific Node JS version.
And we are ready to create node project with npm init like we did in tutorial on how to scrap data from a website. After creating a project we should be able to install dependency libraries and in our case we need Puppeteer, so type:
# npm install puppeteer
And this is the breaking point for Node Package Manager (npm) on arm64 CPUs. There’s no Chromium browser binary that’s needed by Puppeteer and Puppeteer installation will probably fail. So we need to install Chromium manually because npm is not able to do that for us. Luckily for us we won’t need to build whole project from the source but we can use well known ports Ubuntu repository to find what we need. Edit this file:
# sudo nano /etc/apt/sources.list
to add these lines at the bottom of the file:
deb [arch=arm64] http://ports.ubuntu.com/ focal main multiverse universe
deb [arch=arm64] http://ports.ubuntu.com/ focal-security main multiverse universe
deb [arch=arm64] http://ports.ubuntu.com/ focal-backports main multiverse universe
deb [arch=arm64] http://ports.ubuntu.com/ focal-updates main multiverse universe
Save and exit. Now type:
# sudo dpkg --print-foreign-architectures
# sudo dpkg --add-architecture arm64
# sudo dpkg --print-foreign-architectures
# sudo apt-get update
# sudo apt install chromium-browser
Chromium browser is hopefully installed and npm will be able to install Puppeteer without errors:
# npm install puppeteer