离线安装vim

下载依赖可以通过docker容器来进行下载,目标服务器也可以是docker容器

centos

  1. 确定目标服务器的版本
cat /etc/redhat-release 
CentOS Linux release 8.1.1911 (Core) 
  1. 修改yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum -y update
  1. 可使用docker下载相应的镜像,进入容器 使用 yum下载 RPM 包及其所有依赖
mkdir -p /opt/soft/vim-lib
#下载相关rpm
yum install --downloaddir=/opt/soft/vim-lib --downloadonly vim
cd /opt/soft/vim-lib
tar -czvf package.tar.gz *
  1. 将package.tar.gz发送到目标服务并安装
mkdir vim-lib
tar -zxvf package.tar.gz -C vim-lib
cd vim-lib
#安装
dpkg -i *.deb
#验证
vim czb-test.sh

ubuntu

  1. 确定目标服务器的版本
cat /etc/os-release 
  1. 修改apt源
cd /etc/apt/
cp sources.list sources.list.backup
echo "">sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse" >> sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse" >> sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse" >> sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse" >> sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse" >> sources.list
echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse" >> sources.list
echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse" >> sources.list
echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse" >> sources.list
echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse" >> sources.list
echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse" >> sources.list
#更新
apt-get update
  1. 下载vim依赖
apt -d install vim
#提示需要安装 libpython3.5 ,libtinfo5 
...
The following packages have unmet dependencies:
 vim : Depends: libpython3.5 (>= 3.5.0~b1) but it is not going to be installed
       Depends: libtinfo5 (>= 6) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
#先下载 libpython3.5 ,libtinfo5 
apt -d install libpython3.5 ,libtinfo5
#下载的包在/var/cache/apt/archives/中
cd /var/cache/apt/archives/
#将所有deb文件压缩到lib-package.tar.gz中
tar -czvf lib-package.tar.gz *.deb
#需要先将lib-package.tar.gz移动到/opt/soft/,否则下载vim包会导致var/cache/apt/archives/的*.deb删掉
mv lib-package.tar.gz /opt/soft/.
#先安装libpython3.5 ,libtinfo5,先安装依赖才能下载安装vim
apt install libpython3.5 ,libtinfo5
#下载vim
apt -d install vim
#下载的包在/var/cache/apt/archives/中
cd /var/cache/apt/archives/
#将所有deb文件压缩到vim-package.tar.gz中
tar -czvf vim-package.tar.gz *.deb
#需要先将lib-package.tar.gz移动到/opt/soft/
mv vim-package.tar.gz /opt/soft/.
  1. 将vim-package.tar.gz,lib-package.tar.gz发送到目标服务并安装
cd /opt/soft
mkdir vim-lib
mkdir lib-lib
tar -zxvf vim-package.tar.gz -C vim-lib
tar -zxvf lib-package.tar.gz -C lib-lib
#先安装依赖
cd lib-lib
#安装依赖
dpkg -i *.deb
cd ../vim-lib
#安装vim依赖
dpkg -i *.deb

总结

vim离线安装不过是个例子,这种方式也可以用在下载其他命令