Linux之安装软件

Linux下安装软件包的方法

  • rpm工具

  • yum工具

  • 源码包


rpm

  • 要想使用rpm包,首先将光驱连接到Linux系统中并挂载
[root@zyxlinux01 ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@zyxlinux01 ~]# cd /mnt
[root@zyxlinux01 mnt]# ls
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@zyxlinux01 mnt]# cd Packages/
[root@zyxlinux01 Packages]# 

里面光驱里所有rpm包都在/Packages目录里

  • rpm包由包名、版本号、发行号、平台、后缀名
yum-utils-1.1.31-24.el7.noarch.rpm
zenity-3.8.0-4.el7.x86_64.rpm
zip-3.0-10.el7.x86_64.rpm
zlib-1.2.7-13.el7.x86_64.rpm
zlib-devel-1.2.7-13.el7.x86_64.rpm
  • rpm -ivh 包文件 安装

  • rpm -Uvh 包文件 升级

  • rpm -e 包名 卸载

  • rpm -qa 查询已经安装的包

  • rpm -q 包名 查询指定的包是否已安装

[root@zyxlinux01 Packages]# rpm -q ppp
ppp-2.4.5-33.el7.x86_64
  • rpm -qi 包名 查询指定包的信息
[root@zyxlinux01 Packages]# rpm -qi ppp
Name        : ppp
Version     : 2.4.5
Release     : 33.el7
Architecture: x86_64
Install Date: 2017年07月09日 星期日 01时16分08秒
Group       : System Environment/Daemons
Size        : 872624
License     : BSD and LGPLv2+ and GPLv2+ and Public Domain
Signature   : RSA/SHA256, 2014年07月04日 星期五 12时34分15秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : ppp-2.4.5-33.el7.src.rpm
Build Date  : 2014年06月10日 星期二 14时27分03秒
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.samba.org/ppp
Summary     : The Point-to-Point Protocol daemon
Description :
The ppp package contains the PPP (Point-to-Point Protocol) daemon and
documentation for PPP support. The PPP protocol provides a method for
transmitting datagrams over serial point-to-point links. PPP is
usually used to dial in to an ISP (Internet Service Provider) or other
organization over a modem and phone line.
  • rpm -ql 包名 列出包安装的文件
[root@zyxlinux01 Packages]# rpm -ql vim-enhanced
/etc/profile.d/vim.csh
/etc/profile.d/vim.sh
/usr/bin/rvim
/usr/bin/vim
/usr/bin/vimdiff
/usr/bin/vimtutor
  • rpm qf 文件绝对路径 查看一个文件是由哪个包所安装
[root@zyxlinux01 Packages]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-1.el7_3.1.x86_64

rpm工具安装或者卸载往往会有一些依赖、被依赖的其他软件,所有在使用过程中不是太方便

反引号的一种用法 (rpm -qf which cd)

[root@zyxlinux01 Packages]# rpm -qf `which cd`
bash-4.2.45-5.el7.x86_64
[root@zyxlinux01 Packages]# rpm -qf `which vim`
vim-enhanced-7.4.160-1.el7_3.1.x86_64

yum工具

自动解决依赖关系,更快捷的安装需要的软件包

  • /etc/yum.repos.d/ :yum的配置文件目录

  • yum list 列出可用的rpm包

  • yum search word :搜索一个包(比较模糊,不够精准)

[root@zyxlinux01 ~]# yum search lrzsz
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.btte.net
 * updates: mirrors.163.com
================================================== N/S matched: lrzsz ==================================================
lrzsz.x86_64 : The lrz and lsz modem communications programs

  名称和简介匹配 only,使用“search all”试试。
  • `yum list |grep 'vim' :比较精准的搜索rpm包
[root@zyxlinux01 ~]# yum list |grep 'vim'
vim-common.x86_64                          2:7.4.160-1.el7_3.1         @updates 
vim-enhanced.x86_64                        2:7.4.160-1.el7_3.1         @updates 
vim-filesystem.x86_64                      2:7.4.160-1.el7_3.1         @updates 
vim-minimal.x86_64                         2:7.4.160-1.el7             @anaconda
golang-vim.noarch                          1.3.3-2.el7_0               extras   
protobuf-vim.x86_64                        2.5.0-8.el7                 base     
vim-X11.x86_64                             2:7.4.160-1.el7_3.1         updates  
vim-minimal.x86_64                         2:7.4.160-1.el7_3.1         updates  
  • yum install -y 包名 : 安装软件包

  • yum grouplist : 列出可用的软件包组

  • yum groupinstall 包组名 : 安装软件包组

  • yum remove 包名 : 卸载软件包

  • yum update 包名 : 升级软件

直接使用yum update会把所有能升级的软件一起升级,包括操作系统、内核等(这个操作通常在刚刚安装完系统时进行)

  • yum provides "/*/命令" :搜索一个命令能由哪些包安装

yum搭建本地仓库

  1. 将光驱镜像挂载到 /mnt
[root@zyxlinux01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@zyxlinux01 ~]# ls !$
ls /mnt/
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
  1. 备份yum配置文件目录
[root@zyxlinux01 ~]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak/
  1. 删除原配置文件目录
[root@zyxlinux01 ~]# rm -rf /etc/yum.repos.d/*
  1. 在`/etc/yum.repos.d/下创建一个新文件并编辑
[root@zyxlinux01 yum.repos.d]# vi dvd.repo

[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpcheck=0
  1. 清除之前的缓存
[root@zyxlinux01 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: dvd
Cleaning up everything
Cleaning up list of fastest mirrors

更换yum仓库源

  1. 下载源文件

wget http://mirrors.163.com/.help/CentOS7-Base-163.repo或者curl -0 http://mirrors.163.com/.help/CentOS7-Base-163.repo

  1. 删除CentOS-Base.repo

yum下载rpm包,安装扩展源epel

  • 安装扩展源

yum install -y epel-release

[root@zyxlinux01 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-Vault.repo
[root@zyxlinux01 yum.repos.d]# yum install -y epel-release

[root@zyxlinux01 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-Vault.repo  epel.repo  epel-testing.repo

再次查看yum list会多出epel仓库的rpm包

  • 下载rpm包
  1. yum install zsh --downlordonly

--downlordonly:表示仅下载

[root@zyxlinux01 yum.repos.d]# yum install zsh --downloadonly

[root@zyxlinux01 yum.repos.d]# ls /var/cache/yum/x86_64/7/updates/packages/
zsh-5.0.2-25.el7_3.1.x86_64.rpm

下载的文件默认存放位置在/var/cache/yum/x86_64/7/下

  1. --downloaddir=/指定目录/:将rpm包下载到指定目录
[root@zyxlinux01 yum.repos.d]# yum install zsh --downloadonly --downloaddir=/tmp/

[root@zyxlinux01 yum.repos.d]# ls /tmp
2.txt  yum.log                                    yum_save_tx.2017-07-22.12-52.IgLwIl.yumtx  zyx00  zyx.txt
d6zsy  yum_save_tx.2017-07-22.12-47.bX7py9.yumtx  zsh-5.0.2-25.el7_3.1.x86_64.rpm            zyxml  zyx.txt.zip
  1. 需要下载已经安装过的rpm包时,使用yum reinstall --downloadonly

源码包安装

首先统一源码包的存放位置为 /usr/local/src/

实例如下

  • 进入/usr/local/src/

  • 下载源码包

[root@zyxlinux01 nginx-1.8.0]# wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.2.34.tar.gz
--2017-07-22 13:17:39--  http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.2.34.tar.gz
正在解析主机 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.6.178, 2402:f000:1:416:101:6:6:178
正在连接 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.6.178|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:7684419 (7.3M) [application/octet-stream]
正在保存至: “httpd-2.2.34.tar.gz”

100%[==============================================================================>] 7,684,419    552KB/s 用时 12s    

2017-07-22 13:17:51 (650 KB/s) - 已保存 “httpd-2.2.34.tar.gz” [7684419/7684419])
  • 解压 tar -zxvf httpd-2.2.34.tar.gz
[root@zyxlinux01 src]# ls
httpd-2.2.34  httpd-2.2.34.tar.gz
[root@zyxlinux01 src]# cd httpd-2.2.34.tar.gz 
[root@zyxlinux01 src]# cd httpd-2.2.34
[root@zyxlinux01 httpd-2.2.34]# ls
ABOUT_APACHE  BuildBin.dsp   configure.in  httpd.mak       LAYOUT        Makefile.in    os                server
acinclude.m4  buildconf      docs          httpd.spec      libhttpd.dep  Makefile.win   README            srclib
Apache.dsw    CHANGES        emacs-style   include         libhttpd.dsp  modules        README.platforms  support
build         config.layout  httpd.dep     INSTALL         libhttpd.mak  NOTICE         README-win32.txt  test
BuildAll.dsp  configure      httpd.dsp     InstallBin.dsp  LICENSE       NWGNUmakefile  ROADMAP           VERSIONING

INSTALL:安装说明文档

  • 安装到/usr/local/apache2/
[root@zyxlinux01 httpd-2.2.34]# ./configure --prefix=/usr/local/apache2
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu

Configuring Apache Portable Runtime library ...

checking for APR... reconfig
configuring package in srclib/apr now
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
Configuring APR library
Platform: x86_64-unknown-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.5.2
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/httpd-2.2.34/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
configure failed for srclib/apr
[root@zyxlinux01 httpd-2.2.34]# echo $?
1

  • 安装完成后,使用 make

  • make install

[root@zyxlinux01 apache2]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules

echo $? :检测上一条命令是否正确,结果非0就是不正确的,如果不正确,则需要检查错误原因并解决。解决之后重新安装一次。(最好每一步操作后都检测一下)

posted @ 2017-09-22 21:11  指环王Raul  阅读(297)  评论(0编辑  收藏  举报