Search code examples
pythonubuntuofflineapt

upgrade python offline - ubuntu apt


I have an Ubuntu VM without internet access. It currently has Python 3.10 installed but I want to update to Python 3.11 (the latest at the time of this post).

On a machine with internet access, I used apt to download Python3.11.

mkdir python_3.11
apt-get --download-only -o Dir::Cache="./python_3.11/" -o Dir::Cache::archives="./python_3.11/" install python3.11

$ ls python_3.11
libpython3.11-minimal_3.11.0~rc1-1~22.04_amd64.deb  pkgcache.bin
libpython3.11-stdlib_3.11.0~rc1-1~22.04_amd64.deb   python3.11-minimal_3.11.0~rc1-1~22.04_amd64.deb
lock                                                python3.11_3.11.0~rc1-1~22.04_amd64.deb
partial                                             srcpkgcache.bin

After transferring the files onto the VM, I tried running sudo dpkg -i on each of the files. This eventually "installed" them but opening a python shell still shows the old 3.10 version. /usr/bin/python3 still points to /usr/bin/python3.10 and this is no /usr/bin/python3.11.

Another thing I've tried

# on the machine im trying to install
sudo apt-get update -oDir::Cache::archives="/path/to/downloaded/packages" --no-install-recommends --no-download
sudo apt-get -oDir::Cache::archives="/path/to/downloaded/packages" --no-install-recommends --no-download install python3.11-minimal

This ends up returning

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

I've since added the following to the download command. python3.11-minimal libpython3.11-stdlib python3.11 libpython3.11-minimal python3.11-venv python3.11-doc binfmt-support python3-pip-whl python3-setuptools-whl. During the install, I'm still getting the same error message on "Unable to fetch some archives".


Solution

  • There are 2 commands that need to be run. I'm not 100% sure the first one (the update) is necessary. It is important that the paths are absolute. Assuming the required packages have been downloaded, it should install.

    apt-get -oDir::Cache::archives="/absolute/path/"  -oDir::Cache="/absolute/path" --no-install-recommends --no-download update 
    apt-get -oDir::Cache::archives="/absolute/path/"  -oDir::Cache="/absolute/path/" --no-install-recommends --no-download install python3.11