Skip to content

Instantly share code, notes, and snippets.

@ai2ys
Last active January 10, 2022 18:16
Show Gist options
  • Save ai2ys/3c10becf47f39acd15ff7b2769189872 to your computer and use it in GitHub Desktop.
Save ai2ys/3c10becf47f39acd15ff7b2769189872 to your computer and use it in GitHub Desktop.
Specify Linux Package versions and Python Library Versions for Installation

Specify Package Version apt-get install

Installing a specific version

Install exactly the specified version, example:

# Installing exactly version '1.20.3-1ubuntu2' of wget
sudo apt-get install wget=1.20.3-1ubuntu2

Install the latest patch for the specified version, example:

# Installing latest patch for wget version '1.20' of wget
sudo apt-get install wget=1.20.*

Retrieving version number for installed package

Retrieve installed version for packages, examples:

# dpkg -s <package name or space separated list of package names> | grep 'Package\|Version'
dpkg -s wget | grep 'Package\|Version'
# Package: wget
# Version: 1.20.3-1ubuntu2

dpkg -s wget git | grep 'Package\|Version'
# Package: wget
# Version: 1.20.3-1ubuntu2
# Package: git
# Version: 1:2.25.1-1ubuntu3.2

Specify Python Library Version pip install

Detailed information: https://www.python.org/dev/peps/pep-0440/#compatible-release

Installing a specific version

Install exactly the specified version, example:

# Installing exactly version 1.21.3
pip install numpy==1.21.3

Install the latest patch for the specified version of a Python library, example:

Symbol Major Minor Patch
== # .# .*
>= # .# .#
~= # .# .#
# equivalent options
pip install libaray_name~=major.minor.patch
pip install libaray_name>=major.minor.patch
pip install libaray_name==major.minor.*

Example for installing NumPy

# Installing latest patch for numpy version 1.21
pip install numpy~=1.21.3

Retrieving version number for installed libary

# pip freeze | grep <library name>
pip freeze | grep numpy
# numpy==1.21.3 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment