[Golang] 使用 yum 在 Centos 7 上安裝 Golang


使用 yum 在 Centos 7 上安裝 Golang

1、首先,先安裝EPEL :

[root@localhost tmp]# yum install epel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.xtom.com.hk
 * extras: mirror.xtom.com.hk
 * updates: mirror.xtom.com.hk
No package epel available.
Error: Nothing to do

如果已安裝過可以略過這個步驟

2、接著使用yum 安裝Golang:

[root@localhost tmp]# yum install go

尋找相關Package

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.xtom.com.hk
 * extras: mirror.xtom.com.hk
 * updates: mirror.xtom.com.hk
Resolving Dependencies
--> Running transaction check
---> Package golang.x86_64 0:1.9.4-1.el7 will be installed
--> Processing Dependency: golang-src = 1.9.4-1.el7 for package: golang-1.9.4-1.el7.x86_64
--> Processing Dependency: golang-bin = 1.9.4-1.el7 for package: golang-1.9.4-1.el7.x86_64
--> Running transaction check
---> Package golang-bin.x86_64 0:1.9.4-1.el7 will be installed
--> Processing Dependency: gcc for package: golang-bin-1.9.4-1.el7.x86_64
---> Package golang-src.noarch 0:1.9.4-1.el7 will be installed
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-28.el7_5.1 will be installed
--> Processing Dependency: cpp = 4.8.5-28.el7_5.1 for package: gcc-4.8.5-28.el7_5.1.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-28.el7_5.1.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.5-28.el7_5.1.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.5-28.el7_5.1.x86_64
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-28.el7_5.1 will be installed
---> Package glibc-devel.x86_64 0:2.17-222.el7 will be installed
--> Processing Dependency: glibc-headers = 2.17-222.el7 for package: glibc-devel-2.17-222.el7.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-222.el7.x86_64
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
---> Package glibc-headers.x86_64 0:2.17-222.el7 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-222.el7.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-222.el7.x86_64
--> Running transaction check
---> Package kernel-headers.x86_64 0:3.10.0-862.9.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================
 Package             Arch        Version                    Repository    Size
===============================================================================
Installing:
 golang              x86_64      1.9.4-1.el7                base         611 k
Installing for dependencies:
 cpp                 x86_64      4.8.5-28.el7_5.1           updates      5.9 M
 gcc                 x86_64      4.8.5-28.el7_5.1           updates       16 M
 glibc-devel         x86_64      2.17-222.el7               base         1.1 M
 glibc-headers       x86_64      2.17-222.el7               base         678 k
 golang-bin          x86_64      1.9.4-1.el7                base          49 M
 golang-src          noarch      1.9.4-1.el7                base         5.1 M
 kernel-headers      x86_64      3.10.0-862.9.1.el7         updates      7.1 M
 libmpc              x86_64      1.0.1-3.el7                base          51 k
 mpfr                x86_64      3.1.1-4.el7                base         203 k

Transaction Summary
===============================================================================
Install  1 Package (+9 Dependent packages)

Total download size: 86 M
Installed size: 282 M

確認Package項目,執行安裝

Is this ok [y/d/N]: y

安裝過程

Downloading packages:
(1/10): glibc-headers-2.17-222.el7.x86_64.rpm             | 678 kB   00:02
golang-1.9.4-1.el7.x86_64.rpm  FAILED
http://mirrors.nwsuaf.edu.cn/centos/7.5.1804/os/x86_64/Packages/golang-1.9.4-1.el7.x86_64.rpm: [Errno 12] Timeout on http://mirrors.nwsuaf.edu.cn/centos/7.5.1804/os/x86_64/Packages/golang-1.9.4-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
cpp-4.8.5-28.el7_5.1.x86_64.rp FAILED
http://mirror.xtom.com.hk/centos/7.5.1804/updates/x86_64/Packages/cpp-4.8.5-28.el7_5.1.x86_64.rpm: [Errno 12] Timeout on http://mirror.xtom.com.hk/centos/7.5.1804/updates/x86_64/Packages/cpp-4.8.5-28.el7_5.1.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
glibc-devel-2.17-222.el7.x86_6 FAILED
http://mirror.xtom.com.hk/centos/7.5.1804/os/x86_64/Packages/glibc-devel-2.17-222.el7.x86_64.rpm: [Errno 12] Timeout on http://mirror.xtom.com.hk/centos/7.5.1804/os/x86_64/Packages/glibc-devel-2.17-222.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
libmpc-1.0.1-3.el7.x86_64.rpm  FAILED
http://repo.virtualhosting.hk/centos/7.5.1804/os/x86_64/Packages/libmpc-1.0.1-3.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.virtualhosting.hk/centos/7.5.1804/os/x86_64/Packages/libmpc-1.0.1-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(2/10): gcc-4.8.5-28.el7_5.1.x86_64.rpm                   |  16 MB   02:27
golang-src-1.9.4-1.el7.noarch. FAILED
http://mirror.xtom.com.hk/centos/7.5.1804/os/x86_64/Packages/golang-src-1.9.4-1.el7.noarch.rpm: [Errno 12] Timeout on http://mirror.xtom.com.hk/centos/7.5.1804/os/x86_64/Packages/golang-src-1.9.4-1.el7.noarch.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
golang-1.9.4-1.el7.x86_64.rpm  FAILED
http://centos.uhost.hk/7.5.1804/os/x86_64/Packages/golang-1.9.4-1.el7.x86_64.rpm: [Errno 12] Timeout on http://centos.uhost.hk/7.5.1804/os/x86_64/Packages/golang-1.9.4-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(3/10): golang-bin-1.9.4-1.el7.x86_64.rpm                 |  49 MB   03:37
(4/10): libmpc-1.0.1-3.el7.x86_64.rpm                     |  51 kB   00:00
(5/10): glibc-devel-2.17-222.el7.x86_64.rpm               | 1.1 MB   00:17
(6/10): golang-1.9.4-1.el7.x86_64.rpm                     | 611 kB   00:01
(7/10): mpfr-3.1.1-4.el7.x86_64.rpm                       | 203 kB   01:39
(8/10): kernel-headers-3.10.0-862.9.1.el7.x86_64.rpm      | 7.1 MB   02:12
(9/10): golang-src-1.9.4-1.el7.noarch.rpm                 | 5.1 MB   00:54
(10/10): cpp-4.8.5-28.el7_5.1.x86_64.rpm                  | 5.9 MB   02:10
-------------------------------------------------------------------------------
Total                                             280 kB/s |  86 MB  05:13
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mpfr-3.1.1-4.el7.x86_64                                    1/10
  Installing : libmpc-1.0.1-3.el7.x86_64                                  2/10
  Installing : cpp-4.8.5-28.el7_5.1.x86_64                                3/10
  Installing : golang-src-1.9.4-1.el7.noarch                              4/10
  Installing : kernel-headers-3.10.0-862.9.1.el7.x86_64                   5/10
  Installing : glibc-headers-2.17-222.el7.x86_64                          6/10
  Installing : glibc-devel-2.17-222.el7.x86_64                            7/10
  Installing : gcc-4.8.5-28.el7_5.1.x86_64                                8/10
  Installing : golang-1.9.4-1.el7.x86_64                                  9/10
  Installing : golang-bin-1.9.4-1.el7.x86_64                             10/10
  Verifying  : kernel-headers-3.10.0-862.9.1.el7.x86_64                   1/10
  Verifying  : golang-bin-1.9.4-1.el7.x86_64                              2/10
  Verifying  : mpfr-3.1.1-4.el7.x86_64                                    3/10
  Verifying  : gcc-4.8.5-28.el7_5.1.x86_64                                4/10
  Verifying  : golang-1.9.4-1.el7.x86_64                                  5/10
  Verifying  : glibc-devel-2.17-222.el7.x86_64                            6/10
  Verifying  : golang-src-1.9.4-1.el7.noarch                              7/10
  Verifying  : cpp-4.8.5-28.el7_5.1.x86_64                                8/10
  Verifying  : glibc-headers-2.17-222.el7.x86_64                          9/10
  Verifying  : libmpc-1.0.1-3.el7.x86_64                                 10/10

Installed:
  golang.x86_64 0:1.9.4-1.el7

Dependency Installed:
  cpp.x86_64 0:4.8.5-28.el7_5.1
  gcc.x86_64 0:4.8.5-28.el7_5.1
  glibc-devel.x86_64 0:2.17-222.el7
  glibc-headers.x86_64 0:2.17-222.el7
  golang-bin.x86_64 0:1.9.4-1.el7
  golang-src.noarch 0:1.9.4-1.el7
  kernel-headers.x86_64 0:3.10.0-862.9.1.el7
  libmpc.x86_64 0:1.0.1-3.el7
  mpfr.x86_64 0:3.1.1-4.el7

Complete!

 

3、最後,環境變數設定:

[root@localhost tmp]# mkdir /var/go
[root@localhost tmp]# vi /etc/profile

請在最後一行,加上以下兩斷

export GOPATH=/var/www/html
export PATH=$PATH:$GOPATH/bin
#:wq

再來請執行 以下語法

source /etc/profile

以上,完成

 

 

 

 

 

 

 


在〈“[Golang] 使用 yum 在 Centos 7 上安裝 Golang”〉中有 1 則留言