离线使用yum·无法使用yum的情况下安装软件·最简单的方法

​ A机器无法使用yum(通常是因为网络原因无法访问yum源),这个时候如需要在A机器上安装软件,常规方法就是自己去下载源码然后进行make install。不过,这种方法最大的弊端就是在isntall过程中可能会牵连出许多依赖包缺失,然后,这些缺失的依赖包又要下在源码进行make install。。。无穷尽也。

例如在一个没有zlib的机器上直接make install git的源码:

[[email protected]]$ make && make install
GIT_VERSION = 2.8.3
    * new build flags
    CC credential-store.o
In file included from credential-store.c:1:0:
cache.h:40:18: fatal error: zlib.h: No such file or directory
 #include 
                  ^
compilation terminated.
make: *** [credential-store.o]

#--------------zlib 缺失--------------#
## zlib也装完了再make就会报错韶关perl,perl再装完了还会报错curl,,,别问我怎么知道的,问就是猜的^.^

​ 这个时候,可以找一台能够使用yum 的机器B,然后在机器B上直接使用yum的「–downloaddir」以及「–downloadonly」参数就可以下载包了,例如「yum -y install tree --downloaddir=/home/gavin/tmp/tree_rpm_pkg --downloadonly」就可下载tree的rpm包,这样下载的包,是包含了完整依赖的(机器B上已经有的包是不会重新下载的,不过可以直接yum remove掉,等包下完了再安装就是了);

示例「下载tree 的rpm包」:

[gavin@ip-10-58-21-17 tree_rpm_pkg]$ ll
total 0
[gavin@ip-10-58-21-17 tree_rpm_pkg]$ pwd
/home/gavin/tmp/tree_rpm_pkg
[gavin@ip-10-58-21-17 tree_rpm_pkg]$ sudo yum -y install tree --downloaddir=/home/gavin/tmp/tree_rpm_pkg --downloadonly
[sudo] password for gavin: 
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                                                                              | 3.7 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.amzn2.0.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                 Arch                                      Version                                                 Repository                                     Size
===============================================================================================================================================================================================
Installing:
 tree                                    x86_64                                    1.6.0-10.amzn2.0.1                                      amzn2-core                                     47 k

Transaction Summary
===============================================================================================================================================================================================
Install  1 Package

Total download size: 47 k
Installed size: 83 k
Background downloading packages, then exiting:
tree-1.6.0-10.amzn2.0.1.x86_64.rpm                                                                                                                                      |  47 kB  00:00:00     
exiting because "Download Only" specified
[gavin@ip-10-58-21-17 tree_rpm_pkg]$ ll
total 52
-rw-r--r-- 1 root root 47640 Mar 25  2020 tree-1.6.0-10.amzn2.0.1.x86_64.rpm
[gavin@ip-10-58-21-17 tree_rpm_pkg]$ 

得到了rpm包之后,直接使用ftp工具或者光盘U盘各种盘,拷贝到无法使用yum 的机器A上,然后使用命令「rpm -ivh *.rpm --nodeps --force」把rpm包装一下就行了;

示例「安装 gcc」:

[[email protected]]$ cd gcc_rpm/
[[email protected]_rpm]$ ll
total 39324
-rw-rw-r-- 1 ec2-user ec2-user  6234536 Feb  9 07:25 cpp-4.8.5-28.el7.x86_64.rpm
-rw-rw-r-- 1 ec2-user ec2-user 16967040 Feb  9 07:25 gcc-4.8.5-28.el7.x86_64.rpm
-rw-rw-r-- 1 ec2-user ec2-user  7534972 Feb  9 07:25 gcc-c++-4.8.5-36.el7.x86_64.rpm
-rw-rw-r-- 1 ec2-user ec2-user  1116252 Feb  9 07:25 glibc-devel-2.17-222.el7.x86_64.rpm
-rw-rw-r-- 1 ec2-user ec2-user   694524 Feb  9 07:25 glibc-headers-2.17-222.el7.x86_64.rpm
-rw-rw-r-- 1 ec2-user ec2-user  7442492 Feb  9 07:25 kernel-headers-3.10.0-862.el7.x86_64.rpm
-rw-rw-r-- 1 ec2-user ec2-user    51732 Feb  9 07:25 libmpc-1.0.1-3.el7.x86_64.rpm
-rw-rw-r-- 1 ec2-user ec2-user   208316 Feb  9 07:24 mpfr-3.1.1-4.el7.x86_64.rpm
[[email protected]_rpm]$ sudo rpm  -ivh  *.rpm --nodeps --force
warning: cpp-4.8.5-28.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Permission denied)
[[email protected]_rpm]$ sudo rpm  -ivh  *.rpm --nodeps --force
warning: cpp-4.8.5-28.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mpfr-3.1.1-4.el7                 ################################# [ 13%]
   2:libmpc-1.0.1-3.el7               ################################# [ 25%]
   3:cpp-4.8.5-28.el7                 ################################# [ 38%]
   4:kernel-headers-3.10.0-862.el7    ################################# [ 50%]
   5:glibc-headers-2.17-222.el7       ################################# [ 63%]
   6:glibc-devel-2.17-222.el7         ################################# [ 75%]
   7:gcc-4.8.5-28.el7                 ################################# [ 88%]
   8:gcc-c++-4.8.5-36.el7             ################################# [100%]
[[email protected]_rpm]$

你可能感兴趣的:(解决方法,linux,yum,离线)