ubuntu的通用源内nginx的预编译版本都是1.18.0版本,想要apt安装nginx的最新预编译版本就需要添加nginx的官方deb源

关键词:ubuntu nginx apt

一、安装操作依赖

sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring

二、导入官方nginx签名密钥

1.获取key

Import an official nginx signing key so apt could verify the packages authenticity. Fetch the key:

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

2.验证下载的文件是否包含正确密钥

Verify that the downloaded file contains the proper key:

gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

The output should contain the full fingerprint 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 as follows:

pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
      573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid                      nginx signing key <signing-key@nginx.com>

如果指纹不一致请删除文件重新下载

If the fingerprint is different, remove the file.

三、编辑apt仓库

这里有两种发行版本,择一安装即可

1.stable 稳定版

To set up the apt repository for stable nginx packages, run the following command:

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

2.mainline 主流版

If you would like to use mainline nginx packages, run the following command instead:

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

四、设置源优先级

使nginx官方源软件包优先于发行版提供的软件包

Set up repository pinning to prefer our packages over distribution-provided ones:

echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx

五、安装nginx

To install nginx, run the following commands:

sudo apt update
sudo apt install nginx

参考

nginx: Linux packages

文章作者:四文鱼Max

本文链接:https://blog.awolon.fun/archives/ubuntu-add-official-nginx-deb-source.html

许可协议:CC BY-SA 4.0

标签: ubuntu, apt, nginx

添加新评论