To install Python 3.13 on Amazon Linux 2 you have to build it from source. The build only works after two swaps: openssl11-devel instead of the stock openssl-devel, and a newer SQLite under /usr/local. Skip either one and make still finishes: without the OpenSSL swap the interpreter has no ssl or hashlib, so pip cannot reach PyPI, and without the SQLite build it has no sqlite3.
This guide is for people running Amazon Linux 2 who can’t move to AL2023 yet. AWS’s Amazon Linux 2 FAQ says AL2 reached its end of support on 2026-06-30 and no longer gets standard security updates, so treat this build as a bridge. We tested every step against the Python 3.13.18 security release on the Amazon Linux 2 image AWS built on 2026-11-27, in November 2026. On AL2023 you need none of this; follow our guide to install Python 3.14 on Amazon Linux 2023 instead.
Why a plain source build fails on Amazon Linux 2
Amazon Linux 2 shipped in 2017, and its base libraries never moved forward. Python 2 is still the interpreter on the PATH, python3 is not installed at all, and both OpenSSL and SQLite come from that era. Here is what the fresh image reports before we touch anything.

Each of those gaps maps to a specific requirement in the Python 3.13 build requirements, and each one fails in a different way:
- OpenSSL 1.0.2k is too old. CPython needs OpenSSL 1.1.1 or newer for the
sslandhashlibmodules, so configure drops both and pip loses HTTPS. - SQLite 3.7.17 is too old. Since 3.13 the
sqlite3module wants SQLite 3.15.2 or newer, and AL2’ssqlite-develnever got past 3.7. - The compiler is fine. AL2’s GCC 7.3 handles the C11 code CPython needs, so the toolchain stays as it is.
The repos tell the rest of the story. Because the python3 package in amzn2-core is 3.7 and amazon-linux-extras no longer offers a newer Python topic (only collectd-python3 came back when we listed it), there is no packaged route. What the core repo does carry is a parallel OpenSSL 1.1.1 package set, which we can confirm with yum.
yum list available python3 openssl11 openssl11-devel sqlite-devel
The openssl11 packages are the ones we’ll build against. sqlite-devel is stuck on the old release, which is why SQLite gets its own build later.

We ran sudo yum -y update on the image first so the build starts from the newest packages AWS still publishes for AL2. The repos keep working after end of support, but nothing new is landing in them, so the versions in that list are effectively final. Plan around them rather than waiting for an update that will not come.
What happens if you build with the stock openssl-devel
Most older guides for this distro install openssl-devel with the other headers and move on. We did the same on purpose, because the failure is silent and it helps to see what it looks like. First the compiler and the development headers that CPython’s optional modules link against.
sudo yum -y install gcc make tar xz wget bzip2-devel libffi-devel zlib-devel xz-devel readline-devel ncurses-devel gdbm-devel libuuid-devel sqlite-devel tk-devel openssl-devel
The transaction ends like this, and gcc --version confirms the compiler it brought in.
tk.x86_64 1:8.5.13-6.amzn2.0.2
xorg-x11-proto-devel.noarch 0:2018.4-1.amzn2.0.2
Complete!
gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-18)
Next, download the source tarball and check it against the SHA-256 on the release page before unpacking. Python 3.13 is in its security-only phase, so each new release ships as source with no installers. That suits us, since a source build is the only option on AL2 anyway.
cd ~
wget -q https://www.python.org/ftp/python/3.13.18/Python-3.13.18.tar.xz # https://www.python.org/downloads/release/python-31318/
echo "abb0102e6d4ae027509bcb82327d9dd85515b44a3ba8ad538cfc5e9847029f68 Python-3.13.18.tar.xz" | sha256sum -c -
tar -xf Python-3.13.18.tar.xz
The checksum line should read Python-3.13.18.tar.xz: OK. Run a plain configure from the source directory and filter for the lines that decide whether TLS and SQLite make it into the build.
cd ~/Python-3.13.18
./configure --prefix=/usr/local 2>&1 | grep -iE "openssl|ssl|sqlite3|_hashlib"
Configure exits with status 0, and that is the trap. It finds OpenSSL and can link against it, then decides the library lacks the APIs the ssl module needs and quietly marks three modules as missing.

If you carried on to make from here, you’d get a python3.13 binary that starts and runs scripts. Then pip install can’t reach PyPI without the ssl module, and anything that imports sqlite3 crashes. The old version of this guide fixed the OpenSSL half and missed the SQLite half, so read those three missing lines every time you configure, not just the exit code.
How to switch the build to OpenSSL 1.1
The openssl11-devel package declares a conflict with openssl-devel (both ship /usr/include/openssl), so yum won’t install them side by side. Remove the old headers first. Only the development package goes away, which means the runtime openssl library that yum, curl and sshd use stays in place.
sudo yum -y remove openssl-devel
sudo yum -y install openssl11 openssl11-devel
Confirm the new library and see where its files went. Because the headers land in the default include path and libssl.so in /usr/lib64, configure finds them without any --with-openssl flag.
openssl11 version
rpm -ql openssl11-devel | grep -E "ssl.h$|\.pc$|libssl.so$"
Our package came back as 1.1.1zj, a build AWS patched in September 2026.

One detail confuses people here. Running pkg-config --cflags openssl11 errors out with “Package ‘libssl’, required by ‘OpenSSL’, not found”, because the package names its files libssl11.pc while openssl11.pc still requires plain libssl. You can ignore it, since CPython’s configure falls back to the standard paths and picks up the 1.1 headers there.
How to build a SQLite new enough for _sqlite3
No newer SQLite package exists for AL2, so we build the amalgamation from sqlite.org into /usr/local. Leave the system sqlite package alone, because yum and rpm depend on it. The download page publishes SHA3-256 hashes, and the new openssl11 binary can compute those where the old 1.0.2 tool cannot, so the swap you just made pays off twice.
cd ~
wget -q https://sqlite.org/2026/sqlite-autoconf-3540100.tar.gz # https://sqlite.org/download.html
openssl11 dgst -sha3-256 sqlite-autoconf-3540100.tar.gz
tar -xf sqlite-autoconf-3540100.tar.gz
cd sqlite-autoconf-3540100
./configure --prefix=/usr/local
make -j"$(nproc)"
sudo make install
Match the printed hash against the one listed for that tarball on the download page. After that, check that the library and its pkg-config file are in place.
ls /usr/local/lib | grep sqlite
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig pkg-config --modversion sqlite3
Our run printed the hash, the four library files that make install placed in /usr/local/lib, and the version pkg-config now reports for that copy.
SHA3-256(sqlite-autoconf-3540100.tar.gz)= b6ced585c750916b1052667239a12c25a7ff34e7f06e1e6e01ecb0427657d9c4
libsqlite3.a
libsqlite3.so
libsqlite3.so.0
libsqlite3.so.3.54.1
3.54.1
Pointing PKG_CONFIG_PATH at /usr/local/lib/pkgconfig is what lets Python’s configure see this copy instead of the system one. On its own that is not enough at run time, though. The loader still finds the system /lib64/libsqlite3.so (the 3.7.17 library) first unless the binary carries an rpath, which is what the next step adds.
How to configure and compile Python 3.13
Go back to the source tree and clear the earlier configure result. The second run adds three things: the pkg-config path for SQLite, profile-guided optimization, and an rpath. With the rpath in place, _sqlite3 loads /usr/local/lib/libsqlite3.so rather than the system library.
cd ~/Python-3.13.18
make distclean
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --prefix=/usr/local --enable-optimizations LDFLAGS="-Wl,-rpath,/usr/local/lib"
Filtering the same lines as before, every check that failed earlier now says yes.

Now compile. With --enable-optimizations the build compiles once, runs the test suite as a training workload, then compiles again using the profile. Expect it to take a few times longer than a plain build, so start it in tmux if your SSH session might drop.
time make -j"$(nproc)"
On our 7 vCPU guest the whole thing took a little over five minutes of wall time. Read the module summary at the end rather than the scroll above it. Only _tkinter is missing, even with tk-devel installed, and we didn’t chase it since it only matters for Tkinter GUIs on a server.

Install with altinstall, not install. The plain target also writes /usr/local/bin/python3, and since /usr/local/bin comes first on the PATH, it silently wins over the repo python3 package. Someone who later installs that package for a tool expecting 3.7 gets the wrong interpreter, whereas altinstall only creates the versioned python3.13 and pip3.13.
sudo make altinstall
The tail of the install log shows the bundled pip being set up. Expect the root warning, because make altinstall runs ensurepip as root.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-26.2.2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.
Take that warning as advice for everything after this point. Install packages into virtual environments rather than into the /usr/local interpreter, so a future point release can replace it without stranding anything you installed.
How to check that ssl and sqlite3 really work
A version string proves the binary runs, not that it linked the right libraries. So import the two modules that broke earlier, print the library versions they report, and look at what the compiled _ssl extension links against.
python3.13 --version
python3.13 -c 'import ssl, sqlite3; print(ssl.OPENSSL_VERSION); print("sqlite", sqlite3.sqlite_version)'
ldd /usr/local/lib/python3.13/lib-dynload/_ssl.cpython-313-x86_64-linux-gnu.so | grep -E "ssl|crypto"
python --version
Python reports OpenSSL 1.1.1zj and SQLite 3.54.1, _ssl resolves to libssl.so.1.1, and the system python is still the untouched 2.7 interpreter.

Run the same ldd check on the SQLite extension module to see the rpath from the configure step doing its job at load time.
ldd /usr/local/lib/python3.13/lib-dynload/_sqlite3.cpython-313-x86_64-linux-gnu.so | grep sqlite
It should point at the copy in /usr/local/lib, not the system library in /lib64 that yum and rpm keep using.
libsqlite3.so => /usr/local/lib/libsqlite3.so (0x00007f0075c24000)
If that line shows the system /lib64/libsqlite3.so instead, the build skipped the LDFLAGS rpath. In that case sqlite3 either fails to import or reports the old release, so rerun configure with the flag and rebuild before you go any further.
How to use Python 3.13 in a virtual environment
The real test of the OpenSSL fix is pip talking to PyPI over TLS. We created a project directory, made a venv with the new interpreter, upgraded pip, installed requests and made one HTTPS call, because that exercises certificate verification end to end.
mkdir -p ~/app && cd ~/app
python3.13 -m venv .venv && source .venv/bin/activate
pip install -q --upgrade pip && pip install -q requests
python -c "import requests; r = requests.get(\"https://pypi.org/simple/requests/\", timeout=10); print(r.status_code, r.raw.version, r.headers[\"content-type\"])"
pip list
A 200 over HTTP/1.1 means the TLS handshake and certificate check both went through the 1.1.1 library. The pip list shows what landed in the venv.

Inside an activated venv, python and pip mean 3.13, so there is no need for aliases in ~/.bashrc. Leave the venv with deactivate.
Why sudo python3.13 says command not found
Systemd units and install scripts hit this one constantly. Your shell finds python3.13 because /usr/local/bin is on your PATH, but sudo replaces PATH with the secure_path from /etc/sudoers. On AL2 that list leaves /usr/local/bin out, so the same command fails as soon as you prefix it.
sudo python3.13 --version
sudo /usr/local/bin/python3.13 --version
sudo grep secure_path /etc/sudoers
The first call fails with command not found, while the absolute path runs the same interpreter without complaint, and the sudoers line shows exactly which directories sudo is willing to search.

Use /usr/local/bin/python3.13 in anything run as root, including ExecStart= lines and cron entries. We’d rather do that than edit secure_path, because that changes the PATH for every sudo command on the box. Better still, point services at the venv’s own bin/python, which is an absolute path by nature and pins the packages too.
Where this build breaks down
The build works, and we’d still only run it as a stopgap. These are the limits we hit or confirmed while testing.
- The OS is out of support. AWS’s FAQ says AL2 no longer gets standard security updates and points everyone at AL2023, which it supports until June 2029. Patching CPython yourself does nothing for the kernel or glibc underneath it.
- OpenSSL 1.1.1 is end of life upstream. The
openssl11package still carries AWS patches, but it’s the oldest series CPython 3.13 accepts, and a later Python release may not build against it at all. - yum stays on Python 2.
/usr/bin/yumstarts with#!/usr/bin/python, so never point/usr/bin/pythonat 3.13 with alternatives or a symlink. That breaks package management outright. - Upgrades are manual. Python 3.13 gets source-only security releases until October 2029. Each one means repeating the download, configure and
altinstallby hand. - No Tkinter. The build left
_tkinterout against AL2’s Tk 8.5 packages, which is harmless on servers but rules out GUI tooling.
To rehearse this on a disposable box, we built our test VM by following the guide to run Amazon Linux 2 on KVM from the qcow2 image. The same approach works for Amazon Linux 2023 on KVM once you start testing the migration. For comparison, the Python 3.13 build for Rocky Linux and AlmaLinux follows the same configure pattern on a distro whose OpenSSL is current. AL2 hosts that also run PHP face the same kind of repo gap, covered in installing PHP 8 on Amazon Linux 2.