添加镜像源
$ sudo vim /etc/apt/sources.list.d/nginx.list
使用mainline
可以获取到最新版本的nginx,配置内容如下:
deb http://mirrors./nginx/mainline/ubuntu/ focal nginx
添加GPG密钥与安装
直接运行sudo apt update
会报错:
W: GPG error: http://mirrors./nginx/ubuntu focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ABF5BD827BD9BF62E: The repository 'http://mirrors./nginx/ubuntu focal InRelease' is not signed.N: Updating from such a repository can't be done securely, and is therefore disabled by default.N: See apt-secure(8) manpage for repository creation and user configuration details.
需要将上面NO_PUBKEY
后面的公钥进行导入(注意根据实际提示替换命令最后的公钥内容)
sudo apt-key adv --keyserver --recv-keys ABF5BD827BD9BF62sudo apt updatesudo apt install -y nginx
安装完成后检查当前nginx版本,与官网上mainline
的最新版本一致
$ nginx -vnginx version: nginx/1.19.1
.9.19更新
换了台Ubuntu 20.04的服务器使用上面的方法进行更新的时候提示:
N: Skipping acquire of configured file 'nginx/binary-i386/Packages' as repository 'http://mirrors./nginx/mainline/ubuntu focal InRelease' doesn't support architecture 'i386'
系统是64位的,apt更新提示不支持i386架构关我毛事儿…翻了下中科大的镜像站目录发现确实不支持32位的架构:
修改一下/etc/apt/sources.list.d/nginx.list
配置,指定系统架构[arch=amd64]
:
deb [arch=amd64] http://mirrors./nginx/mainline/ubuntu/ focal nginx
再重新apt update
:
1 package can be upgraded. Run 'apt list --upgradable' to see it.N: Skipping acquire of configured file 'nginx/binary-i386/Packages' as repository 'http://mirrors./nginx/mainline/ubuntu focal InRelease' doesn't support architecture 'i386'
重新apt upgrade
:
The following packages have been kept back:nginx0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
擦~还是不能更新,翻了下stackoverflow,手工重新安装nginx:
$ sudo apt install nginx -y$ sudo systemctl restart nginx# 重新安装后需要重启一下服务(重装后服务是停着的)$ nginx -vnginx version: nginx/1.19.2# OJBK了