{"id":622,"date":"2022-07-25T15:34:53","date_gmt":"2022-07-25T13:34:53","guid":{"rendered":"https:\/\/www.simernes.com\/?p=622"},"modified":"2023-01-01T14:38:15","modified_gmt":"2023-01-01T13:38:15","slug":"install-python-3-7-without-sudo-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/www.simernes.com\/?p=622","title":{"rendered":"Install Python 3.7 without sudo on Ubuntu 22.04"},"content":{"rendered":"\n<p>This guide will show you how you can install Python 3.7 (or any other version) for a single user without using sudo. Note that it will only be available for that user, and can be convenient if you don&#8217;t want to affect other users on the same machine.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Download the source code<\/h2>\n\n\n\n<p>First download the source. As I&#8217;m writing this guide, the latest version is 3.7.9.<\/p>\n\n\n\n<p>Also, extract the source.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget <a href=\"https:\/\/www.python.org\/ftp\/python\/3.7.9\/Python-3.7.9.tar.xz\">https:\/\/www.python.org\/ftp\/python\/3.7.9\/Python-3.7.9.tar.xz<\/a>\ntar -xf Python-3.7.9.tar.xz<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. Install build dependencies (somewhat optional)<\/h2>\n\n\n\n<p>Your system may or may not have these already installed. To build python with all its features, we will install the minimum build dependencies, plus some optional once to get features like ssl for python. You can choose to ignore some of these if you want.<\/p>\n\n\n\n<p>If you don&#8217;t have access to sudo at all, you should try to compile following the later steps without installing these dependencies, and if necessary you can try to install the dependencies for your current user (this is kind of advanced, but should be possible).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y build-essential libreadline-dev libssl-dev libsqlite3-dev libgdbm-dev libgdbm-compat-dev libbz2-dev tk-dev liblzma-dev libffi-dev<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. Compile the source code<\/h2>\n\n\n\n<p>Enter the source directory, and run the commands to build the source. You should replace the home directory with your own user (I used &#8220;simen&#8221;)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd Python-3.7.9\n.\/configure --enable-optimizations --prefix=\/home\/simen\/.local\nmake<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. Install it for the user<\/h2>\n\n\n\n<p>Finally we will install the compiled binaries for the user. Make sure not to use sudo here, or it will be installed for all users. <\/p>\n\n\n\n<p>In the same directory as before run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make install<\/code><\/pre>\n\n\n\n<p>Finally, we have to add the user-specific bin folder to our path, unless it is already.<\/p>\n\n\n\n<p>Check if it&#8217;s in your path with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo $PATH<\/code><\/pre>\n\n\n\n<p>It should look something like, and should start with <code>\/home\/simen\/.local\/bin<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/home\/simen\/.local\/bin:\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/usr\/games:\/usr\/local\/games:\/snap\/bin<\/code><\/pre>\n\n\n\n<p>If it doesn&#8217;t include your <code>.local\/bin<\/code> folder, edit the \/home\/simen\/.bashrc file and add to the top:<\/p>\n\n\n\n<p><code>export PATH=$HOME\/.local\/bin:$PATH<\/code><\/p>\n\n\n\n<p>It&#8217;s important that <code>$HOME\/.local\/bin<\/code> is at the beginning of the path, so that it overrides the python3 binary if it installed somewhere else in your system.<\/p>\n\n\n\n<p>Save and close the file.<\/p>\n\n\n\n<p>Log out and log back in to refresh your PATH variable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Test that it works<\/h2>\n\n\n\n<p>Now, finally run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python3<\/code><\/pre>\n\n\n\n<p>You should be running Python 3.7!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide will show you how you can install Python 3.7 (or any other version) for a single user without using sudo. Note that it will only be available for that user, and can be convenient if you don&#8217;t want to affect other users on the same machine. 1. Download the source code First download<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[34,17,35],"class_list":["post-622","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-computerscience","tag-opensource","tag-python","no-featured-content"],"_links":{"self":[{"href":"https:\/\/www.simernes.com\/index.php?rest_route=\/wp\/v2\/posts\/622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simernes.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.simernes.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.simernes.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simernes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=622"}],"version-history":[{"count":6,"href":"https:\/\/www.simernes.com\/index.php?rest_route=\/wp\/v2\/posts\/622\/revisions"}],"predecessor-version":[{"id":634,"href":"https:\/\/www.simernes.com\/index.php?rest_route=\/wp\/v2\/posts\/622\/revisions\/634"}],"wp:attachment":[{"href":"https:\/\/www.simernes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.simernes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.simernes.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}