Ubuntu installs Nginx through apt

The advantage of using apt to install is that it is convenient to upgrade in a unified way, and there is no need to manually install it separately. By default, nginx already supports apt-get installation, but the installed package is an older 10.x version. We can use the latest stable version of nginx by adding the nginx deb installation source, and keep the latest unfinalized version of nginx through the update and upgrade commands in real time.

add apt-key

sudo apt-key add nginx_signing.key

Since the latest stable version of nginx needs to be downloaded from the deb source officially designated by nginx, a trusted public key (PGP) needs to be added first. You can copy and save the following public key as a file named nginx_signing.key (you can also download it from the official website ):

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2.0.22 (GNU/Linux)

mQENBE5OMmIBCAD+FPYKGriGGf7NqwKfWC83cBV01gabgVWQmZbMcFzeW+hMsgxH
W6iimD0RsfZ9oEbfJCPG0CRSZ7ppq5pKamYs2+EJ8Q2ysOFHHwpGrA2C8zyNAs4I
QxnZZIbETgcSwFtDun0XiqPwPZgyuXVm9PAbLZRbfBzm8wR/3SWygqZBBLdQk5TE
fDR+Eny/M1RVR4xClECONF9UBB2ejFdI1LD45APbP2hsN/piFByU1t7yK2gpFyRt
97WzGHn9MV5/TL7AmRPM4pcr3JacmtCnxXeCZ8nLqedoSuHFuhwyDnlAbu8I16O5
XRrfzhrHRJFM1JnIiGmzZi6zBvH0ItfyX6ttABEBAAG0KW5naW54IHNpZ25pbmcg
a2V5IDxzaWduaW5nLWtleUBuZ2lueC5jb20+iQE+BBMBAgAoAhsDBgsJCAcDAgYV
CAIJCgsEFgIDAQIeAQIXgAUCV2K1+AUJGB4fQQAKCRCr9b2Ce9m/YloaB/9XGrol
kocm7l/tsVjaBQCteXKuwsm4XhCuAQ6YAwA1L1UheGOG/aa2xJvrXE8X32tgcTjr
KoYoXWcdxaFjlXGTt6jV85qRguUzvMOxxSEM2Dn115etN9piPl0Zz+4rkx8+2vJG
F+eMlruPXg/zd88NvyLq5gGHEsFRBMVufYmHtNfcp4okC1klWiRIRSdp4QY1wdrN
1O+/oCTl8Bzy6hcHjLIq3aoumcLxMjtBoclc/5OTioLDwSDfVx7rWyfRhcBzVbwD
oe/PD08AoAA6fxXvWjSxy+dGhEaXoTHjkCbz/l6NxrK3JFyauDgU4K4MytsZ1HDi
MgMW8hZXxszoICTTiQEcBBABAgAGBQJOTkelAAoJEKZP1bF62zmo79oH/1XDb29S
YtWp+MTJTPFEwlWRiyRuDXy3wBd/BpwBRIWfWzMs1gnCjNjk0EVBVGa2grvy9Jtx
JKMd6l/PWXVucSt+U/+GO8rBkw14SdhqxaS2l14v6gyMeUrSbY3XfToGfwHC4sa/
Thn8X4jFaQ2XN5dAIzJGU1s5JA0tjEzUwCnmrKmyMlXZaoQVrmORGjCuH0I0aAFk
RS0UtnB9HPpxhGVbs24xXZQnZDNbUQeulFxS4uP3OLDBAeCHl+v4t/uotIad8v6J
SO93vc1evIje6lguE81HHmJn9noxPItvOvSMb2yPsE8mH4cJHRTFNSEhPW6ghmlf
Wa9ZwiVX5igxcvaIRgQQEQIABgUCTk5b0gAKCRDs8OkLLBcgg1G+AKCnacLb/+W6
cflirUIExgZdUJqoogCeNPVwXiHEIVqithAM1pdY/gcaQZmIRgQQEQIABgUCTk5f
YQAKCRCpN2E5pSTFPnNWAJ9gUozyiS+9jf2rJvqmJSeWuCgVRwCcCUFhXRCpQO2Y
Va3l3WuB+rgKjsQ=
=EWWI
-----END PGP PUBLIC KEY BLOCK-----

Then execute the following command:

sudo apt-key add nginx_signing.key

Set apt's deb source

First of all, you need to clarify the current ubuntu version. When installing nginx, different ubuntu versions correspond to different nginx installation packages. The comparison is as follows:

Version installation package alias Applicable platform
14.04 trusty x86_64, i386, aarch64/arm64
16.04 great x86_64, i386, ppc64el, aarch64/arm64
17.10 artful x86_64, i386

Open apt's installation source configuration file - /etc/apt/sources.list. Add at the end of the file:

  • deb http://nginx.org/packages/ubuntu/ code nginx
  • deb-src http://nginx.org/packages/ubuntu/ code nginx

Note that the code marked in red needs to be replaced with the corresponding alias according to the above table according to the version number of Ubuntu.

After setting, use the checklog command to see that it has now switched to the latest stable version. (no log output, only a version number)

install nginx

Finally update the list of installation sources and then install nginx.

apt-get update
apt-get install nginx

Install the latest released version

In addition to the stable version, you can also install the latest release version (Mainline) through apt. Just modify the path of the installation source - modify the deb source in /etc/apt/sources.list to:

  • deb http://nginx.org/packages/mainline/ubuntu/ code nginx
  • deb-src http://nginx.org/packages/mainline/ubuntu/ code nginx

For more installation methods, see the official website

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325041535&siteId=291194637