Install a Specific Version of a Package

~1 minute read


I wanted to install cncjs on Raspberry, but a specific version of Node.js had to be installed. By default, the latest version is installed whatever if there are many sources.

Check Package Availability


Before installation, you can type apt-cache madison to see if there are many versions available.

apt-cache madison packagename

Here is the output:

pi@raspberrypi:~ $ apt-cache madison nodejs
nodejs | 10.19.0~dfsg1-1 | http://raspbian.raspberrypi.org/raspbian buster/main
nodejs | 7.10.1-2nodesource1~buster1 | https://deb.nodesource.com/node_7.x buster
nodejs | 7.10.1-2nodesource1~buster1 | https://deb.nodesource.com/node_7.x buster

Or with another display with apt-cache policy:

pi@raspberrypi:~ $ apt-cache policy nodejs
nodejs:
Installed: (none)
Candidate: 10.19.0~dfsg1-1
Version table:
10.19.0~dfsg1-1 500
500 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages
7.10.1-2nodesource1~buster1 500
500 https://deb.nodesource.com/node_7.x buster/main armhf Packages

Install the Specific Version


We can use apt-get to proceed with the installation:

apt-get install package=version -V

The -V parameter will give more information.

Simulate Installation


We can simulate the installation to check if everything will go well.

apt-get install -s package apt-get install -s node=7.10.1-2nodesource1~buster1

Check Installed Version of a Package


dpkg -l | grep nodejs

Avoid Further Updates


Finally, in order to avoid the update of the version installed to a more recent one, we need to freeze the package. To do so:

apt-mark hold nodejs # Freeze

Or to unlock it afterwards:

apt-mark unhold nodejs # Unfreeze

If apt update is done, we will have the recent package in the list –upgradable. Nevertheless, it will be kept back when performing apt upgrade.

pi@raspberrypi:~ $ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
nodejs
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

Published

Category

Notes

Stay Connected

Tags