GNU Wget是一款以非交互模式從Web下載文件的免費應用程序。其支持HTTP、HTTPS、FTP協議,同時支持HTTP代理。目前最新版本是1.18,於09 June, 2016釋出。關於wget的特點(feature),具體見Overview

本人工作電腦的操作系統是CentOS Linux release 7.2.1511 (Core),默認安裝的wget版本是1.14,版本較爲陳舊,不支持很多新特性,比如--show-progress(進度條顯示)。無法通過yum升級版本,便想通過源代碼編譯安裝最新版本的wget。

GNU Wget的官方文檔可從https://www.gnu.org/software/wget/manual/下載。

Preparation

準備操作

Installing Essential Packages

1
sudo yum install -y gcc openssl openssl-devel gnutls gnutls-devel

Remove Older Version Without Dependency

因包之間存在依賴關係,故而無法直接通過命令rpm -eyum remove卸載(會先進行包依賴性檢查),提示google-chromeipa-clientipa-python等應用程序依賴於wget

此時可通過指定rpm的驗證選項(verify-option)--nodeps,在使用-e卸載時不進行依賴性檢查。

–nodeps Don’t do a dependency check before installing or upgrading a package.

執行如下命令卸載wget

1
sudo rpm -ev --nodeps $(rpm -qa | grep ^wget)

Download Source Package & Extract

wget的HTTP下載地址是 http://ftp.gnu.org/gnu/wget/,此處選擇1.18版本,鏈接爲

1
http://ftp.gnu.org/gnu/wget/wget-1.18.tar.xz

注意:將源碼包下載到~/Downloads目錄,解壓至/tmp/wget目錄

具體執行命令

1
2
3
4
5
6
cd ~/Downloads && curl -O -# http://ftp.gnu.org/gnu/wget/wget-1.18.tar.xz
#或
wget -N --direcory-prefix ~/Downloads http://ftp.gnu.org/gnu/wget/wget-1.18.tar.xz

[[ ! -d /tmp/wget ]] && (umask 022;mkdir -p /tmp/wget) || sudo rm -rf /tmp/wget/*
tar xf ~/Downloads/wget-1.18.tar.xz -C /tmp/wget --strip-components=1

解壓後

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[[email protected] wget]$ ls
ABOUT-NLS ChangeLog doc m4 Makefile.in README util
aclocal.m4 configure GNUmakefile MAILING-LIST msdos src
AUTHORS configure.ac INSTALL maint.mk NEWS testenv
build-aux COPYING lib Makefile.am po tests
[[email protected] wget]$ ls -lh
total 2.3M
-rw-r--r-- 1 flying flying 92K Dec 12 2015 ABOUT-NLS
-rw-rw-r-- 1 flying flying 73K Jun 6 23:13 aclocal.m4
-rw-rw-r-- 1 flying flying 2.2K Jan 19 2016 AUTHORS
drwxrwxr-x 3 flying flying 4.0K Jun 10 00:25 build-aux
-rw-rw-r-- 1 flying flying 733K Jun 10 00:25 ChangeLog
-rwxrwxr-x 1 flying flying 1.1M Jun 10 00:12 configure
-rw-rw-r-- 1 flying flying 23K Mar 25 2016 configure.ac
-rw-rw-r-- 1 flying flying 35K Mar 9 2015 COPYING
drwxrwxr-x 2 flying flying 4.0K Jun 10 00:25 doc
-rw-rw-r-- 1 flying flying 4.5K Jun 10 00:13 GNUmakefile
-rw-rw-r-- 1 flying flying 16K Feb 28 2015 INSTALL
drwxrwxr-x 4 flying flying 8.0K Jun 10 00:25 lib
drwxrwxr-x 2 flying flying 8.0K Jun 10 00:25 m4
-rw-rw-r-- 1 flying flying 1.6K Feb 20 2016 MAILING-LIST
-rw-rw-r-- 1 flying flying 62K Dec 12 2015 maint.mk
-rw-rw-r-- 1 flying flying 2.9K Jan 19 2016 Makefile.am
-rw-rw-r-- 1 flying flying 66K Jun 6 23:13 Makefile.in
drwxrwxr-x 2 flying flying 57 Jun 10 00:25 msdos
-rw-rw-r-- 1 flying flying 35K Jun 10 00:10 NEWS
drwxrwxr-x 2 flying flying 4.0K Jun 10 00:25 po
-rw-rw-r-- 1 flying flying 4.0K Jan 19 2016 README
drwxrwxr-x 2 flying flying 4.0K Jun 10 00:25 src
drwxrwxr-x 8 flying flying 4.0K Jun 10 00:25 testenv
drwxrwxr-x 3 flying flying 4.0K Jun 10 00:25 tests
drwxrwxr-x 2 flying flying 84 Jun 10 00:25 util
[[email protected] wget]$

Compiling Installation

在目錄/tmp/wget下執行如下操作命令

1
2
3
4
5
6
7
8
# 指定安裝路徑,啓用特性,檢測依賴的外部環境,生成Makefile文件
./configure --prefix=/usr --sysconfdir=/etc --mandir=/usr/share/man --docdir=/usr/share/doc/wget --with-ssl=openssl

#根據Makefile文件構建應用程序
sudo make -j 4

#安裝
sudo make install

編譯安裝完成後,通過如下方式查看

New Version Check

可正常查看新版本wget的manual文檔

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[[email protected] ~]$ which wget
/usr/bin/wget
[[email protected] ~]$ man wget | tail -1
GNU Wget 1.18 2016-11-03 WGET(1)
[[email protected] ~]$ wget -V
GNU Wget 1.18 built on linux-gnu.

-cares +digest -gpgme +https +ipv6 -iri +large-file -metalink +nls
+ntlm +opie -psl +ssl/openssl

Wgetrc:
/etc/wgetrc (system)
Locale:
/usr/share/locale
Compile:
gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/etc/wgetrc"
-DLOCALEDIR="/usr/share/locale" -I. -I../lib -I../lib -DHAVE_LIBSSL
-DNDEBUG
Link:
gcc -DHAVE_LIBSSL -DNDEBUG -lpcre -luuid -lssl -lcrypto -lz
ftp-opie.o openssl.o http-ntlm.o ../lib/libgnu.a

Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://www.gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Originally written by Hrvoje Niksic <[email protected]>.
Please send bug reports and questions to <[email protected]>.
[[email protected] ~]$ wget --help | grep "show-progress"
--show-progress display the progress bar in any verbosity mode
[[email protected] ~]$

Downloading Test

執行如下命令進行測試

1
wget -N -nv --directory-prefix=/tmp --show-progress http://mirrors.nwsuaf.edu.cn/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1511.iso

:命令中的下載鏈接來自CentOS官網的Download CentOS頁面中的Minimal ISO

截圖如下:

Errors Occuring

以下爲操作過程中遇到的報錯

Package requirements (gnutls) were not met

執行./configure命令

1
./configure --prefix=/usr --sysconfdir=/etc --libdir=/lib64 --mandir=/usr/share/man --docdir=/usr/share/doc/wget --with-openssl

出現如下報錯

1
2
3
configure: error: Package requirements (gnutls) were not met:

No package 'gnutls' found

查詢是否安裝gnutls

1
2
3
4
5
6
[[email protected] ~]$ rpm -qa | grep gnutls*
gnutls-dane-3.3.8-14.el7_2.x86_64
gnutls-utils-3.3.8-14.el7_2.x86_64
gnutls-3.3.8-14.el7_2.x86_64
gnutls-3.3.8-14.el7_2.i686
[[email protected] ~]$

發現未安裝gnutls-devel,執行如下命令安裝

1
sudo yum install gnutls-devel

再次執行./configure命令成功生成Makefile文件

/lib64/libcrypto.so.10: could not read symbols: Invalid operation

執行sudo make -j 4時報如下錯

1
2
3
/bin/ld: ../lib/libgnu.a(sha1.o): undefined reference to symbol '[email protected]@libcrypto.so.10'
/bin/ld: note: '[email protected]@libcrypto.so.10' is defined in DSO /lib64/libcrypto.so.10 so try adding it to the linker command line
/lib64/libcrypto.so.10: could not read symbols: Invalid operation

調整./configure參數,將--with-ssl=openssl更改爲--with-openssl

1
2
3
4
5
# 更改後參數
./configure --prefix=/usr --sysconfdir=/etc --libdir=/lib64 --mandir=/usr/share/man --docdir=/usr/share/doc/wget --with-openssl

# 更改前參數
./configure --prefix=/usr --sysconfdir=/etc --mandir=/usr/share/man --docdir=/usr/share/doc/wget --with-ssl=openssl

再次執行sudo make -j 4,成功構建Makefile文件。

提示如下信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
configure: Summary of build options:

Version: 1.18
Host OS: linux-gnu
Install prefix: /usr
Compiler: gcc
CFlags: -DHAVE_LIBSSL -DNDEBUG
LDFlags:
Libs: -lpcre -luuid -lssl -lcrypto -lz
SSL: openssl
Zlib: yes
PSL: no
Digest: yes
NTLM: yes
OPIE: yes
Debugging: yes
Assertions: no
Valgrind: Valgrind testing not enabled
Metalink: no
Resolver: libc, --bind-dns-address and --dns-servers not available
GPGME: no

Older Version Info

因舊版本wget是以rpm包形式安裝,故可通過rpm命令查詢其相關信息

:引用的引文來自命令rpm的幫助文檔,可通過命令man rpm查看。

rpm -i info

應用程序相關信息

Display package information, including name, version, and description. This uses the –queryformat if one was specified.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[[email protected] ~]$ rpm -qi wget
Name : wget
Version : 1.14
Release : 10.el7_0.1
Architecture: x86_64
Install Date: Thu 03 Nov 2016 04:17:57 PM CST
Group : Applications/Internet
Size : 2055418
License : GPLv3+
Signature : RSA/SHA256, Fri 31 Oct 2014 01:41:14 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : wget-1.14-10.el7_0.1.src.rpm
Build Date : Fri 31 Oct 2014 01:35:17 AM CST
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.gnu.org/software/wget/
Summary : A utility for retrieving files using the HTTP or FTP protocols
Description :
GNU Wget is a file retrieval utility which can use either the HTTP or
FTP protocols. Wget features include the ability to work in the
background while you are logged out, recursive retrieval of
directories, file name wildcard matching, remote file timestamp
storage and comparison, use of Rest with FTP servers and Range with
HTTP servers to retrieve files over slow or unstable connections,
support for Proxy servers, and configurability.
[[email protected] ~]$

rpm -l list

應用程序安裝後生成的所有文件列表

List files in package.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[[email protected] ~]$ rpm -ql wget
/etc/wgetrc
/usr/bin/wget
/usr/share/doc/wget-1.14
/usr/share/doc/wget-1.14/AUTHORS
/usr/share/doc/wget-1.14/COPYING
/usr/share/doc/wget-1.14/MAILING-LIST
/usr/share/doc/wget-1.14/NEWS
/usr/share/doc/wget-1.14/README
/usr/share/doc/wget-1.14/sample.wgetrc
/usr/share/info/wget.info.gz
/usr/share/locale/be/LC_MESSAGES/wget.mo
/usr/share/locale/bg/LC_MESSAGES/wget.mo
/usr/share/locale/ca/LC_MESSAGES/wget.mo
/usr/share/locale/cs/LC_MESSAGES/wget.mo
/usr/share/locale/da/LC_MESSAGES/wget.mo
/usr/share/locale/de/LC_MESSAGES/wget.mo
/usr/share/locale/el/LC_MESSAGES/wget.mo
/usr/share/locale/en_GB/LC_MESSAGES/wget.mo
/usr/share/locale/eo/LC_MESSAGES/wget.mo
/usr/share/locale/es/LC_MESSAGES/wget.mo
/usr/share/locale/et/LC_MESSAGES/wget.mo
/usr/share/locale/eu/LC_MESSAGES/wget.mo
/usr/share/locale/fi/LC_MESSAGES/wget.mo
/usr/share/locale/fr/LC_MESSAGES/wget.mo
/usr/share/locale/ga/LC_MESSAGES/wget.mo
/usr/share/locale/gl/LC_MESSAGES/wget.mo
/usr/share/locale/he/LC_MESSAGES/wget.mo
/usr/share/locale/hr/LC_MESSAGES/wget.mo
/usr/share/locale/hu/LC_MESSAGES/wget.mo
/usr/share/locale/id/LC_MESSAGES/wget.mo
/usr/share/locale/it/LC_MESSAGES/wget.mo
/usr/share/locale/ja/LC_MESSAGES/wget.mo
/usr/share/locale/lt/LC_MESSAGES/wget.mo
/usr/share/locale/nb/LC_MESSAGES/wget.mo
/usr/share/locale/nl/LC_MESSAGES/wget.mo
/usr/share/locale/pl/LC_MESSAGES/wget.mo
/usr/share/locale/pt/LC_MESSAGES/wget.mo
/usr/share/locale/pt_BR/LC_MESSAGES/wget.mo
/usr/share/locale/ro/LC_MESSAGES/wget.mo
/usr/share/locale/ru/LC_MESSAGES/wget.mo
/usr/share/locale/sk/LC_MESSAGES/wget.mo
/usr/share/locale/sl/LC_MESSAGES/wget.mo
/usr/share/locale/sr/LC_MESSAGES/wget.mo
/usr/share/locale/sv/LC_MESSAGES/wget.mo
/usr/share/locale/tr/LC_MESSAGES/wget.mo
/usr/share/locale/uk/LC_MESSAGES/wget.mo
/usr/share/locale/vi/LC_MESSAGES/wget.mo
/usr/share/locale/zh_CN/LC_MESSAGES/wget.mo
/usr/share/locale/zh_TW/LC_MESSAGES/wget.mo
/usr/share/man/man1/wget.1.gz

rpm -s state

顯示應用程序包中文件的狀態

Display the states of files in the package (implies -l). The state of each file is one of normal, not installed, or replaced.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[[email protected] ~]$ rpm -qs wget
normal /etc/wgetrc
normal /usr/bin/wget
normal /usr/share/doc/wget-1.14
normal /usr/share/doc/wget-1.14/AUTHORS
normal /usr/share/doc/wget-1.14/COPYING
normal /usr/share/doc/wget-1.14/MAILING-LIST
normal /usr/share/doc/wget-1.14/NEWS
normal /usr/share/doc/wget-1.14/README
normal /usr/share/doc/wget-1.14/sample.wgetrc
normal /usr/share/info/wget.info.gz
normal /usr/share/locale/be/LC_MESSAGES/wget.mo
normal /usr/share/locale/bg/LC_MESSAGES/wget.mo
normal /usr/share/locale/ca/LC_MESSAGES/wget.mo
normal /usr/share/locale/cs/LC_MESSAGES/wget.mo
normal /usr/share/locale/da/LC_MESSAGES/wget.mo
normal /usr/share/locale/de/LC_MESSAGES/wget.mo
normal /usr/share/locale/el/LC_MESSAGES/wget.mo
normal /usr/share/locale/en_GB/LC_MESSAGES/wget.mo
normal /usr/share/locale/eo/LC_MESSAGES/wget.mo
normal /usr/share/locale/es/LC_MESSAGES/wget.mo
normal /usr/share/locale/et/LC_MESSAGES/wget.mo
normal /usr/share/locale/eu/LC_MESSAGES/wget.mo
normal /usr/share/locale/fi/LC_MESSAGES/wget.mo
normal /usr/share/locale/fr/LC_MESSAGES/wget.mo
normal /usr/share/locale/ga/LC_MESSAGES/wget.mo
normal /usr/share/locale/gl/LC_MESSAGES/wget.mo
normal /usr/share/locale/he/LC_MESSAGES/wget.mo
normal /usr/share/locale/hr/LC_MESSAGES/wget.mo
normal /usr/share/locale/hu/LC_MESSAGES/wget.mo
normal /usr/share/locale/id/LC_MESSAGES/wget.mo
normal /usr/share/locale/it/LC_MESSAGES/wget.mo
normal /usr/share/locale/ja/LC_MESSAGES/wget.mo
normal /usr/share/locale/lt/LC_MESSAGES/wget.mo
normal /usr/share/locale/nb/LC_MESSAGES/wget.mo
normal /usr/share/locale/nl/LC_MESSAGES/wget.mo
normal /usr/share/locale/pl/LC_MESSAGES/wget.mo
normal /usr/share/locale/pt/LC_MESSAGES/wget.mo
normal /usr/share/locale/pt_BR/LC_MESSAGES/wget.mo
normal /usr/share/locale/ro/LC_MESSAGES/wget.mo
normal /usr/share/locale/ru/LC_MESSAGES/wget.mo
normal /usr/share/locale/sk/LC_MESSAGES/wget.mo
normal /usr/share/locale/sl/LC_MESSAGES/wget.mo
normal /usr/share/locale/sr/LC_MESSAGES/wget.mo
normal /usr/share/locale/sv/LC_MESSAGES/wget.mo
normal /usr/share/locale/tr/LC_MESSAGES/wget.mo
normal /usr/share/locale/uk/LC_MESSAGES/wget.mo
normal /usr/share/locale/vi/LC_MESSAGES/wget.mo
normal /usr/share/locale/zh_CN/LC_MESSAGES/wget.mo
normal /usr/share/locale/zh_TW/LC_MESSAGES/wget.mo
normal /usr/share/man/man1/wget.1.gz
[[email protected] ~]$

rpm -c configfiles

應用程序提供的配置文件

List only configuration files (implies -l).

1
2
[[email protected] ~]$ rpm -qc wget
/etc/wgetrc

rpm -d docfiles

應用程序提供的文檔

List only documentation files (implies -l).

1
2
3
4
5
6
7
8
9
[[email protected] ~]$ rpm -qd wget
/usr/share/doc/wget-1.14/AUTHORS
/usr/share/doc/wget-1.14/COPYING
/usr/share/doc/wget-1.14/MAILING-LIST
/usr/share/doc/wget-1.14/NEWS
/usr/share/doc/wget-1.14/README
/usr/share/doc/wget-1.14/sample.wgetrc
/usr/share/info/wget.info.gz
/usr/share/man/man1/wget.1.gz
  • 應用程序的依賴關係
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    [[email protected] ~]$ rpm -qR wget
    /bin/sh
    /bin/sh
    /sbin/install-info
    /sbin/install-info
    config(wget) = 1.14-10.el7_0.1
    libc.so.6()(64bit)
    libc.so.6(GLIBC_2.11)(64bit)
    libc.so.6(GLIBC_2.14)(64bit)
    libc.so.6(GLIBC_2.15)(64bit)
    libc.so.6(GLIBC_2.17)(64bit)
    libc.so.6(GLIBC_2.2.5)(64bit)
    libc.so.6(GLIBC_2.3)(64bit)
    libc.so.6(GLIBC_2.3.4)(64bit)
    libc.so.6(GLIBC_2.4)(64bit)
    libc.so.6(GLIBC_2.8)(64bit)
    libcrypto.so.10()(64bit)
    libcrypto.so.10(libcrypto.so.10)(64bit)
    libdl.so.2()(64bit)
    libidn.so.11()(64bit)
    libidn.so.11(LIBIDN_1.0)(64bit)
    libpcre.so.1()(64bit)
    libssl.so.10()(64bit)
    libssl.so.10(libssl.so.10)(64bit)
    libuuid.so.1()(64bit)
    libuuid.so.1(UUID_1.0)(64bit)
    libz.so.1()(64bit)
    rpmlib(CompressedFileNames) <= 3.0.4-1
    rpmlib(FileDigests) <= 4.6.0-1
    rpmlib(PayloadFilesHavePrefix) <= 4.0-1
    rtld(GNU_HASH)
    rpmlib(PayloadIsXz) <= 5.2-1
    [[email protected] ~]$

rpm provides

應用程序提供的功能

List capabilities this package provides.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[[email protected] ~]$ rpm --provides wget
RPM version 4.11.3
Copyright (C) 1998-2002 - Red Hat, Inc.
This program may be freely redistributed under the terms of the GNU GPL

Usage: rpm [-aKfgpqVcdLilsiv?] [-a|--all] [-f|--file] [-g|--group]
[-p|--package] [--pkgid] [--hdrid] [--triggeredby] [--whatrequires]
[--whatprovides] [--nomanifest] [-c|--configfiles] [-d|--docfiles]
[-L|--licensefiles] [--dump] [-l|--list] [--queryformat=QUERYFORMAT]
[-s|--state] [--nofiledigest] [--nofiles] [--nodeps] [--noscript]
[--allfiles] [--allmatches] [--badreloc] [-e|--erase <package>+]
[--excludedocs] [--excludepath=<path>] [--force]
[-F|--freshen <packagefile>+] [-h|--hash] [--ignorearch] [--ignoreos]
[--ignoresize] [-i|--install] [--justdb] [--nodeps] [--nofiledigest]
[--nocontexts] [--noorder] [--noscripts] [--notriggers]
[--nocollections] [--oldpackage] [--percent] [--prefix=<dir>]
[--relocate=<old>=<new>] [--replacefiles] [--replacepkgs] [--test]
[-U|--upgrade <packagefile>+] [-D|--define 'MACRO EXPR']
[--undefine=MACRO] [-E|--eval 'EXPR'] [--macros=<FILE:...>]
[--nodigest] [--nosignature] [--rcfile=<FILE:...>] [-r|--root ROOT]
[--dbpath=DIRECTORY] [--querytags] [--showrc] [--quiet]
[-v|--verbose] [--version] [-?|--help] [--usage] [--scripts]
[--setperms] [--setugids] [--conflicts] [--obsoletes] [--provides]
[--requires] [--info] [--changelog] [--xml] [--triggers] [--last]
[--dupes] [--filesbypkg] [--fileclass] [--filecolor] [--fscontext]
[--fileprovide] [--filerequire] [--filecaps]
[[email protected] ~]$

Reference

Change Logs

  • 2016.11.03 18:23 Thu Asia/Shanghai
    • 初稿完成

  • Note Time: 2016.10.25 17:42 Tue
  • Note Location: Asia/Shanghai
  • Writer: lempstacker