如何使用yum在RHEL/CentOS 6/7/8上安装wget

时间:2020-01-09 10:44:15  来源:igfitidea点击:

我正在尝试使用wget http://url语法下载文件,但出现错误:

bash: wget: command not found
bash:wget:找不到命令

我该如何解决这个问题?
如何使用yum命令在CentOS/RHEL版本8、7或者6服务器上安装wget?

GNU Wget是一个免费的开源软件包,用于使用HTTP,HTTPS和FTP(使用最广泛的Internet协议)检索文件。

GNU/wget可能未安装在您的系统上,这是使用yum命令安装的方法。

如何使用yum安装wget命令

打开终端应用程序或者使用ssh客户端登录,然后执行以下yum命令以在CentOS/RHEL 7上安装wget:

$ sudo yum install wget

输出示例:
使用yum命令在CentOS/RHEL上安装GNU/wget

关于Fedora Linux用户的说明

使用以下dnf命令在Fedora 24上安装wget:

$ sudo dnf install wget

如何在CentOS 7或者RHEL 6上安装wget

$ sudo yum install wget

在CentOS 8或者RHEL 8上安装wget

再次使用相同的命令:

$ sudo yum install wget

输出示例:

Red Hat Update Infrastructure 3 Client Configur 1.9 kB/s | 2.1 kB     00:01    
Red Hat Enterprise Linux 8 for x86_64 - AppStre 5.6 MB/s | 7.7 MB     00:01    
Red Hat Enterprise Linux 8 for x86_64 - BaseOS   16 MB/s | 4.7 MB     00:00    
Dependencies resolved.
================================================================================
Package  Arch       Version               Repository                      Size
================================================================================
Installing:
wget     x86_64     1.19.5-7.el8_0.1      rhel-8-appstream-rhui-rpms     734 k
 
Transaction Summary
================================================================================
Install  1 Package
 
Total download size: 734 k
Installed size: 2.8 M
Is this ok [y/N]: y
Downloading Packages:
wget-1.19.5-7.el8_0.1.x86_64.rpm                5.9 MB/s | 734 kB     00:00    
-------------------------------------------------------------------------------
Total                                           5.3 MB/s | 734 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : wget-1.19.5-7.el8_0.1.x86_64                           1/1 
  Running scriptlet: wget-1.19.5-7.el8_0.1.x86_64                           1/1 
  Verifying        : wget-1.19.5-7.el8_0.1.x86_64                           1/1 
 
Installed:
  wget-1.19.5-7.el8_0.1.x86_64                                                  
 
Complete!

我如何使用wget命令?

语法为:

wget url
wget [options] http://url
wget [options] ftp://url

用法和示例

要从互联网下载文件,请执行:

$ wget https://www.theitroad.local/files/adduser.txt

输出示例:

--2015-11-22 08:45:26--  https://www.theitroad.local/files/adduser.txt
Resolving www.theitroad.local (www.theitroad.local)... 75.126.153.202
Connecting to www.theitroad.local (www.theitroad.local)|75.126.153.202|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1022 [text/plain]
Saving to: 'adduser.txt'
 
100%[=====================================- ] 1,022       --.-K/s   in 0s      
 
2015-11-22 08:45:27 (59.4 MB/s) - 'adduser.txt' saved [1022/1022]

要将wget与代理身份验证一起使用,请执行:

$ export https_proxy="https://server1.theitroad.local:3128/"
$ wget --proxy-user "USERNameHere" --proxy-password "PASSWORDHere" http://url-here

要将wget与用户名和密码一起用于FTP/HTTP文件检索,请使用:

$ wget --user=NAME --password='PASSWORD' url

要在后台下载大文件,请执行:

$ wget -bqc http://path-to-freebsd-mirros-url/freebsd-lastest.iso

您可以使用以下语法通过wget恢复中断的下载:

$ wget -c http://url/large.file.tar.gz
$ wget --continue https://url/file.iso

其他用法是使用wget存档网站:

$ wget -nprk 'https://www.some-url-here/'

创建~/.wgetrc文件

$HOME/.wgetrc文件充当GNU wget的初始化文件。
您可以其中存储选项。
这是我的示例$HOME/.wgetrc文件:

# sample file 
# Try ipv6 addresses first
prefer-family = IPv6
 
# Setup proxy
https_proxy = http://server1.theitroad.local:3128/
http_proxy = http://server1.theitroad.local:3128/
ftp_proxy = http://server1.theitroad.local:3128/
 
# Setup the credentials for both http/ftp
user=Hyman
password=OhMyCoolPasswordHere