Home > front end >  Install Nginx on ubuntu 22.04.1 from source and then use package manager
Install Nginx on ubuntu 22.04.1 from source and then use package manager

Time:02-04

I'm using Nginx repository to make and make install Nginx from source on server. But in some articles they ran apt install nginx at least! My steps:

 wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
    tar xzf /usr/src/nginx-${NGINX_VERSION}.tar.gz

And then:

cd /usr/src/nginx-${NGINX_VERSION} && \
    ./configure \
    --prefix=/etc/nginx \
    --sbin-path=/usr/bin/nginx \
    --conf-path=/etc/nginx/nginx.conf \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --add-module=/usr/src/nginx-modules/incubator-pagespeed-ngx-${NPS_VERSION}-stable \
    --with-pcre \
    --pid-path=/var/run/nginx.pid \
    --with-http_ssl_module \
    --user=nginx \
    --group=nginx \
    --with-http_gunzip_module \
    --with-http_gzip_static_module \
    --with-http_v2_module \
    --with-http_flv_module \
    --with-http_mp4_module \
    --with-compat \
    --with-http_slice_module \
    --with-stream_ssl_module \
    --modules-path=/usr/lib/nginx/modules

and run

make && make install

Define a user:

  adduser --system --no-create-home --shell /bin/false --group --disabled-login nginx

Till now everything is perfect. In my case before install the nginx from package manager my nginx version was 1.23.1 (stable version) and after install it from package manager apt install nginx it goes (1.18)

  1. Why we need to install Nginx from package managers(like apt in this case) when we did it from source?
  2. How can I set some specific options when I use package manager to install the Nginx?

CodePudding user response:

Nginx maintenairs publish compiled nginx binaries with some predefined options. https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#prebuilt

Those binaries may not fit for everyone or every usage. One can compile nginx from source code and use it as you do.

But in some articles they ran apt install nginx at least!

Tutorials does not tend to complicate the learning process.

Why we need to install Nginx from package managers (like apt in this case) when we did it from source?

You don't have to use any package manager at all. But if you install nginx by using apt it will try to remove your custom binary. This is why you get a different nginx version.

How can I set some specific options when I use package manager to install the Nginx?

Nginx has mainline and stable binaries published at different repositories. Mainline - Includes the latest features and bug fixes and is always up to date.

https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#installing-a-prebuilt-ubuntu-package-from-the-official-nginx-repository

You can specify a package version when using apt

apt update
apt list -a nginx
apt install nginx=<specific-version...>

https://askubuntu.com/questions/92019/how-to-install-specific-ubuntu-packages-with-exact-version

nginx -V shows a nginx binary's configure arguments. You may use it to compile your custom nginx binary.

Hope, this helps.

  • Related