{"id":14620,"date":"2022-02-01T09:23:54","date_gmt":"2022-02-01T09:23:54","guid":{"rendered":"https:\/\/linuxways.net\/?p=14620"},"modified":"2022-02-01T09:23:54","modified_gmt":"2022-02-01T09:23:54","slug":"how-to-install-nginx-on-ubuntu-20-04-lts-using-source-code","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-nginx-on-ubuntu-20-04-lts-using-source-code\/","title":{"rendered":"How to Install Nginx on Ubuntu 20.04 LTS Using Source Code"},"content":{"rendered":"<h2>What is Nginx?<\/h2>\n<p><a href=\"https:\/\/nginx.org\/en\/\">Nginx<\/a> is open-source software that works as a web server, reverse proxy, load balancer and so much more. It was specially designed to render maximum performance and high stability.<\/p>\n<p>The software follows a master-slave architecture, with one master process maintaining multiple slave processes. Nginx was developed by a Russian developer Igor Sysoev as he was frustrated with the Apache web server and wanted a better replacement that could handle 10,000 concurrent connections with low memory usage. Thanks to him, the Nginx web server came into being. Today, Nginx serves some of the world\u2019s top websites and its growth seems to be only going up.<\/p>\n<p>Now let\u2019s see how can we get Nginx on our system with a few easy steps.<\/p>\n<h2>Installation Guide<\/h2>\n<h3>Prerequisites:<\/h3>\n<ul>\n<li><a href=\"https:\/\/ubuntu.com\/download\/server\">Ubuntu Server 20.04 LTS<\/a><\/li>\n<li>An account with root access<\/li>\n<li>Required Packages (mentioned throughout the tutorial)<\/li>\n<\/ul>\n<h3>Deployment Methods:<\/h3>\n<p>To install Nginx on Ubuntu server, we have two methods:<\/p>\n<ul>\n<li>With the help of the Operating system\u2019s built-in packages manager<\/li>\n<li>By building Nginx from the source code<\/li>\n<\/ul>\n<p>For this tutorial, we have followed the second method. I will show you how you can install Nginx on your Ubuntu server with the help of its source code. Let\u2019s begin!<\/p>\n<h4>Step 1: Update and Upgrade Operating System<\/h4>\n<p>Before beginning the installation, update and upgrade your operating system with the help of the command below so that you only have updated packages on your server.<\/p>\n<pre>sudo apt update &amp;&amp; sudo apt upgrade -y<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"315\" height=\"30\" class=\"wp-image-14621\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-722.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-722.png 315w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-722-300x29.png 300w\" sizes=\"auto, (max-width: 315px) 100vw, 315px\" \/><\/p>\n<h4>Step 2: Add latest Nginx PPA (Mainline)<\/h4>\n<p>This step will commence the installation process. To begin, add latest Nginx PPA by running the command below. In this tutorial, we are installing the mainline PPA.<\/p>\n<pre>sudo add-apt-repository ppa:ondrej\/nginx-mainline -y &amp;&amp; sudo apt update<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"572\" height=\"21\" class=\"wp-image-14622\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-723.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-723.png 572w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-723-300x11.png 300w\" sizes=\"auto, (max-width: 572px) 100vw, 572px\" \/><\/p>\n<h4>Step 3: Install Nginx:<\/h4>\n<p>After installing the PPA and updating the repository list, you will install Nginx with this command:<\/p>\n<pre>sudo apt install nginx-core nginx-common nginx nginx-full<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"464\" height=\"23\" class=\"wp-image-14623\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-724.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-724.png 464w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-724-300x15.png 300w\" sizes=\"auto, (max-width: 464px) 100vw, 464px\" \/><\/p>\n<p>After running this command, you may be asked if you want to keep or replace your existing \/etc\/nginx\/nginx.conf configuration file during installation. We recommend that you keep this existing config file by pressing n. This will allow a copy of the file to be made that you can use in the future if needed.<\/p>\n<h4>Step 4: Add Nginx source code to the repository<\/h4>\n<p>When installing PPA, by default the source code will not be installed. First, you will have to manually enable it. To do that, open the configuration file in \/etc\/apt\/sources.list.d with an editor as shown below:<\/p>\n<pre>sudo nano \/etc\/apt\/sources.list.d\/ondrej-ubuntu-nginx-mainline-*.list<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"557\" height=\"21\" class=\"wp-image-14624\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-725.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-725.png 557w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-725-300x11.png 300w\" sizes=\"auto, (max-width: 557px) 100vw, 557px\" \/><\/p>\n<p>Now locate this line and uncomment it by removing the hash symbol.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"605\" height=\"30\" class=\"wp-image-14625\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-726.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-726.png 605w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-726-300x15.png 300w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><\/p>\n<p>This is how it should look like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1258\" height=\"139\" class=\"wp-image-14626\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-727.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-727.png 1258w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-727-300x33.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-727-1024x113.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-727-768x85.png 768w\" sizes=\"auto, (max-width: 1258px) 100vw, 1258px\" \/><\/p>\n<p>Now save the file by pressing control + X, then Y and hit enter. The changes will be saved.<\/p>\n<p>Now update the repository list like this:<\/p>\n<pre>sudo apt update<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"129\" height=\"27\" class=\"wp-image-14627\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-728.png\" \/><\/p>\n<h4>Step 5: Download Nginx source<\/h4>\n<p>Next, we will download Nginx source code in case you need to compile a dynamic module later. To do that, you need to download and add the source package in the location \/etc\/local\/src\/nginx.<\/p>\n<h5>Create a directory<\/h5>\n<p>Make a directory like this:<\/p>\n<pre>sudo mkdir \/usr\/local\/src\/nginx &amp;&amp; cd \/usr\/local\/src\/nginx<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"472\" height=\"26\" class=\"wp-image-14628\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-729.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-729.png 472w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-729-300x17.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/p>\n<h5>Install dependencies and download the package<\/h5>\n<p>Now download the source package by running the command below:<\/p>\n<pre>sudo apt install dpkg-dev -y &amp;&amp; sudo apt source nginx<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"448\" height=\"34\" class=\"wp-image-14629\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-730.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-730.png 448w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-730-300x23.png 300w\" sizes=\"auto, (max-width: 448px) 100vw, 448px\" \/><\/p>\n<p>After running the command, you may come across an error as shown below. It is safe to ignore it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"454\" height=\"59\" class=\"wp-image-14630\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-731.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-731.png 454w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-731-300x39.png 300w\" sizes=\"auto, (max-width: 454px) 100vw, 454px\" \/><\/p>\n<h4>Step 6: Verify Nginx source version<\/h4>\n<p>Run the ls command to list down the directory\u2019s files:<\/p>\n<pre>ls<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"29\" height=\"25\" class=\"wp-image-14631\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-732.png\" \/><\/p>\n<p>This is how the list will appear in your \/usr\/src\/local\/nginx directory:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"102\" class=\"wp-image-14632\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-733.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-733.png 470w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-733-300x65.png 300w\" sizes=\"auto, (max-width: 470px) 100vw, 470px\" \/><\/p>\n<p>Now run the command below to make sure the source package version is the same as the Nginx version you just installed on your Operating System.<\/p>\n<pre>nginx -v<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"82\" height=\"25\" class=\"wp-image-14633\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-734.png\" \/><\/p>\n<p>You should get a similar output as shown below. This means the source package and the Nginx Operating System should have the same version number. In our case, it is 1.21.1.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"224\" height=\"33\" class=\"wp-image-14634\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-735.png\" \/><\/p>\n<p>If you have made it this far, congratulations, you have successfully installed Nginx.<\/p>\n<h3>How to remove Nginx<\/h3>\n<p>Now that we have seen how to install Nginx, let\u2019s also have a look at how to uninstall it.<\/p>\n<h4>Step 1: Stop Nginx:<\/h4>\n<p>To do that, first of all, stop Nginx as it will be running by using this command:<\/p>\n<pre>sudo systemctl stop nginx<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"212\" height=\"18\" class=\"wp-image-14635\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-736.png\" \/><\/p>\n<h4>Step 2: Remove Nginx<\/h4>\n<p>Now delete Nginx installation by running the following command:<\/p>\n<pre>sudo apt-get purge nginx -y &amp;&amp; sudo apt autoremove nginx -y<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"492\" height=\"22\" class=\"wp-image-14636\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-737.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-737.png 492w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-737-300x13.png 300w\" sizes=\"auto, (max-width: 492px) 100vw, 492px\" \/><\/p>\n<p>After this, Nginx will no longer be on your operating system.<\/p>\n<p>In this tutorial, you saw how you can easily install Nginx on your Ubuntu server with the help of a few easy-to-follow commands. You also saw how you can remove Nginx from your system with the help of two simple commands.<\/p>\n<p>To see how you can setup Nginx as reverse proxy on Ubuntu 20.04, visit:<\/p>\n<p><a href=\"https:\/\/vitux.com\/nginx-performance-tuning\/\">https:\/\/linuxways.net\/ubuntu\/how-to-set-up-nginx-as-reverse-proxy-on-ubuntu-20-04\/<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>What is Nginx? Nginx is open-source software that works as a web server, reverse proxy, load balancer and so much more. It was specially designed to render maximum&hellip;<\/p>","protected":false},"author":1,"featured_media":14671,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[149,100],"class_list":["post-14620","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-nginx","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=14620"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14620\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/14671"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=14620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=14620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=14620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}