a.当咱们须要在多台电脑安装同一个软件,而且这个软件很大,下载须要很长时间时
b.须要安装软件的ubuntu不能上网python
系统是 ubuntu-16.04.5-server-amd64,默认已经安装好了python3,版本为3.5.2nginx
更改ubuntu的更新源为阿里云,默认的速度太慢了数据库
sudo vi /etc/apt/sources.list
内容以下:ubuntu
deb 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
经过以下指令下载XXXX软件所须要的deb包,好比安装python3-pipvim
sudo apt-get -y install python3-pip
执行完上述指令后,XXXX软件的安装包就下载到了/var/cache/apt/archives目录下安全
在项目根目录新建文件夹offlinePackage服务器
sudo mkdir /offlinePackage
将下载的deb包拷贝到上述新建的文件夹下网络
sudo cp -r /var/cache/apt/archives /offlinePackage
修改文件夹的权限,可读可写可执行工具
sudo chmod 777 -R /offlinePackage/
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盘或服务器
插入U盘或光盘,将offlinePackage.tar.gz复制到根目录下,解压
sudo tar zxvf offlinePackage.tar.gz -C /
注意:咱们在添加以前能够先将原来的源备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.back
将安装包所在和源路径添加到系统源source.list
sudo vi /etc/apt/sources.list
内容以下:
deb file:/// offlinePackage/
注意:offlinePackage前面有一个空格
sudo apt-get update
输出:
W: 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
注意:
兼容性问题,若是咱们制做安装包时,用的是64位的ubuntu,那么该离线包只能在其余64位系统上安装。
有些软件对ubuntu server和ubuntu desktop版也不兼容。总之,在什么系统下制做的离线包,就在什么系统下安装。
查看pip3版本
pip3 -V
输出:
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
说明安装成功了!
本文参考连接:
https://blog.csdn.net/wangqiulin123456/article/details/39582269
上线使用的是file方式,只能本机使用。那么其余服务器要使用,就不行了!
这个时候,须要使用http方式。可让局域网的其余服务器使用!
sudo apt-get install -y nginx
这里不使用域名,直接访问IP地址做为主页!
注释掉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
若是出现如下提示,表示ok
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
加载配置
nginx -s reload
访问url: http://192.168.91.128/ ,效果以下:
编辑配置文件
sudo vim /etc/apt/sources.list
最后一行增长
deb http://192.168.91.128 /
注意:保证有空格,不然会提示格式错误。
最后一个是斜杠
使用apt-get update来更新一下
sudo apt-get update
以后,就能够安装软件了!
务必注意:使用apt-get install -y 软件名,后面必定要带--allow-unauthenticated,由于它是私有的,尚未签名!
本文从参考连接: