Step 2: Install Prerequisites<\/strong><\/h2>\n\n\n\nYou’ll need some prerequisites to build Python from source. Install the necessary packages by running:<\/p>\n\n\n\n
$ sudo apt install -y build-essential libssl-dev libffi-dev libbz2-dev libreadline-dev libsqlite3-dev zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev liblzma-dev tk-dev<\/code><\/pre>\n\n\n\nStep 3: Download Python 3.12 Source Code<\/strong><\/h2>\n\n\n\nNext, download the latest Python 3.12 source code from the official Python website. You can use wget<\/code> for this purpose:<\/p>\n\n\n\n$ wget https:\/\/www.python.org\/ftp\/python\/3.12.0\/Python-3.12.0.tgz<\/code><\/pre>\n\n\n\nStep 4: Extract the Downloaded File<\/strong><\/h2>\n\n\n\nExtract the downloaded tarball file:<\/p>\n\n\n\n
$ tar -xf Python-3.12.0.tgz<\/code><\/pre>\n\n\n\nStep 5: Compile and Install Python 3.12<\/strong><\/h2>\n\n\n\nNavigate to the extracted directory:<\/p>\n\n\n\n
$ cd Python-3.12.0<\/code><\/pre>\n\n\n\nNow, configure the build environment:<\/p>\n\n\n\n
$ .\/configure --enable-optimizations<\/code><\/pre>\n\n\n\nThe --enable-optimizations<\/code> flag optimizes the Python binary by running multiple tests, which can significantly speed up the compilation process but will take longer to complete.<\/p>\n\n\n\nCompile and install Python 3.12:<\/p>\n\n\n\n
$ make -j $(nproc)\n$ sudo make altinstall<\/code><\/pre>\n\n\n\nThe make altinstall<\/code> command prevents overwriting the default system Python binary, ensuring that your existing Python environment remains intact.<\/p>\n\n\n\nStep 6: Verify the Installation<\/strong><\/h2>\n\n\n\nOnce the installation is complete, verify that Python 3.12 has been installed correctly by checking the version:<\/p>\n\n\n\n
$ python3.12 --version<\/code><\/pre>\n\n\n\nYou should see an output similar to:<\/p>\n\n\n\n
$ Python 3.12.0<\/code><\/pre>\n\n\n\nStep 7: Set Up a Virtual Environment (Optional)<\/strong><\/h2>\n\n\n\nIt’s a good practice to use virtual environments to manage your Python projects. This keeps dependencies isolated and avoids conflicts. Create a virtual environment using venv<\/code>:<\/p>\n\n\n\n$ python3.12 -m venv myenv<\/code><\/pre>\n\n\n\nActivate the virtual environment:<\/p>\n\n\n\n
$ source myenv\/bin\/activate<\/code><\/pre>\n\n\n\nYou can now install packages within this virtual environment using pip<\/code>:<\/p>\n\n\n\n$ pip install <package_name><\/code><\/pre>\n\n\n\nTo deactivate the virtual environment, simply run:<\/p>\n\n\n\n
$ deactivate<\/code><\/pre>\n\n\n\nConclusion<\/strong><\/h2>\n\n\n\nCongratulations! You’ve successfully installed Python 3.12 on your Ubuntu 24.04 LTS system. With the latest version of Python, you’re now equipped to take advantage of the newest features and improvements. Whether you’re developing applications, automating tasks, or exploring data science, Python 3.12 provides a robust and efficient platform to support your projects.<\/p>\n","protected":false},"excerpt":{"rendered":"
Python 3.12 has arrived with a host of new features and performance improvements, making it a must-have for developers and enthusiasts alike. Whether you’re working on web development, data science,…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,27,16,18],"tags":[193,354,424,433,449,471,475,573,591,598],"yoast_head":"\n
How to Install Python 3.12 on Ubuntu 24.04 LTS Noble Numbat<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n