Newer
Older
til / python / 20231223_install_python_from_source.html

<h3>Install Python from Source</h3>
<h5>Saturday, Dec 23, 2023</h5>

<p>
  Trying to update from Python3.9 to 3.11 using <code>apt get</code> or <code>apt install</code> proved 
  to be a pain in the ass because of gpg keyring, <code>apt add-key</code> deprecated.
</p>

<p>
  Turns out installing from source is much easier though it takes a considerably longer time to compile and install.
</p>

<p>
  I followed the steps from <a href="#ref1">[1]</a> which I have copied here
</p>

<pre>
sudo apt-get update
sudo apt-get install gdebi-core

sudo apt-get install \
    curl \
    gcc \
    libbz2-dev \
    libev-dev \
    libffi-dev \
    libgdbm-dev \
    liblzma-dev \
    libncurses-dev \
    libreadline-dev \
    libsqlite3-dev \
    libssl-dev \
    make \
    tk-dev \
    wget \
    zlib1g-dev

export PYTHON_VERSION=3.11.7
export PYTHON_MAJOR=3

curl -O https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz
tar -xvzf Python-${PYTHON_VERSION}.tgz
cd Python-${PYTHON_VERSION}

./configure \
    --prefix=/opt/python/${PYTHON_VERSION} \
    --enable-shared \
    --enable-optimizations \
    --enable-ipv6 \
    LDFLAGS=-Wl,-rpath=/opt/python/${PYTHON_VERSION}/lib,--disable-new-dtags
make
sudo make install
</pre>

<p>
  Find out where the current python binary is at with
</p>
<pre>
  which python3
</pre>

<p>
  Navigate to the output, delete the symbolic links to the old version.  
  Create new symbolic links to the newly installed version.  New version was installed
  in <code>/opt/python/3.11.7</code>
</p>


<a id="ref1" href="https://docs.posit.co/resources/install-python-source/" target="_blank">[1] : Install Python Source</a>