Ubuntu制作本地安装源
- 应用场景
- 离线安装包的制作(可联网电脑)
- 更新源
- 安装软件
- 生成依赖关系
- 在另外一台Ubuntu上离线安装
- 安装
- 使用deb http方式安装
- 安装nginx
- 更新ubuntu数据库,并安装应用
应用场景
- 当我们需要在多台电脑安装同一个软件,并且软件很大,下载需要很长时间
- 需要安装软件的ubuntu不能上网。
离线安装包的制作(可联网电脑)
- 可联网电脑要与不能联网电脑系统一致
- 修改可联网电脑源,使用国内源,加快软件下载速度
- 系统ubuntu20.0.4
更新源
sudo vi /etc/apt/sources.listdeb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu xenial-security main restricted
deb http://mirrors.aliyun.com/ubuntu xenial-security universe
deb http://mirrors.aliyun.com/ubuntu xenial-security multiverse
安装软件
sudo apt-get -y install python3-pip
执行完上述指令后,XXXX
软件的安装包就下载到了/var/cache/apt/archives
目录下
生成依赖关系
### 新建一个文件夹
sudo mkdir /offlinePackage# 将下载的deb包拷贝到上述新建的文件夹下
sudo cp -r /var/cache/apt/archives /offlinePackage# 修改文件夹权限
sudo chmod 777 -R /offlinePackage/# 建立deb包的依赖关系
sudo dpkg-scanpackages /offlinePackage/ /dev/null |gzip >/offlinePackage/Packages.gz
如果出现错误:sudo: dpkg-scanpackages: command not found,则需要安装dpkg-dev工具
sudo apt-get install dpkg-dev
# 打包成压缩包
sudo tar zcvf offlinePackage.tar.gz /offlinePackage/
保存打包后的offlinePackage.tar.gz
文件到U盘或服务器
在另外一台Ubuntu上离线安装
#
# 将offlinePackage.tar.gz复制到根目录下,解压
sudo tar zxvf offlinePackage.tar.gz -C /# 将安装包所在和源路径添加到系统源source.list
sudo vi /etc/apt/sources.list
deb [trusted=yes] file:/// offlinePackage/
注意:offlinePackage前面有一个空格
# 更新源
sudo apt-get updateW: The repository 'file: offlinePackage/ Release' does not have a Release file.N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.N: See apt-secure(8) manpage for repository creation and user configuration details.# 大概意思是,这是不安全的更新源
安装
此时,在没有网络的情况下,我们就可以安装我们之间下载的XXXX软件了。比如安装python3-pip
,注意:由于上面已经提示不安全了,所以安装软件时,必须要加--allow-unauthenticated
,否则报错 E: There were unauthenticated packages and -y was used without --allow-unauthenticated
sudo apt-get -y install python3-pip --allow-unauthenticated
使用deb http方式安装
上线使用的是file方式,只能本机使用。那么其他服务器要使用,就不行了! 这个时候,需要使用http方式。可以让局域网的其他服务器使用!
安装nginx
sudo apt-get install -y nginx# 搭建项目索引页
sudo vim /etc/nginx/nginx.conf# 找到以下内容,将sites-enabled注释掉
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;# 进入目录conf.d,新建文件deb.conf
vim /etc/nginx/conf.d/deb.conf
server {listen 80;server_name localhost;root /offlinePackage;location / {autoindex on;}}# 检查配置文件是否正确
sudo nginx -t# 加载配置
nginx -s reload
更新ubuntu数据库,并安装应用
# 编辑配置文件
sudo vim /etc/apt/sources.list
# 最后一行增加, 最后一个是斜杠。 注意:保证有空格,否则会提示格式错误。
# 添加 [trusted=yes] 后,使用apt-get install 安装时不用再添加--allow-unauthenticated,否则安装时需要一定要带--allow-unauthenticated ,安装命令为 apt-get install -y 软件名 --allow-unauthenticated
deb [trusted=yes] http://nginx_ip /# 使用apt-get update来更新一下
sudo apt-get update