当前位置: 首页 > 工具软件 > Fedora Func > 使用案例 >

Fedora31 Linux 安装Go基础开发环境

淳于兴朝
2023-12-01

安装Go

[yeqiang@localhost ~]$ sudo dnf install golang golang-docs golang-bin golang-shared
[sudo] password for yeqiang: 
Last metadata expiration check: 2:00:00 ago on Tue 11 Aug 2020 02:35:36 PM CST.
Dependencies resolved.
================================================================================
 Package                   Arch        Version               Repository    Size
================================================================================
Installing:
 golang                    x86_64      1.13.14-1.fc31        updates      632 k
 golang-docs               noarch      1.13.14-1.fc31        updates      2.4 M
 golang-shared             x86_64      1.13.14-1.fc31        updates       25 M
Installing dependencies:
 annobin                   x86_64      8.78-4.fc31           updates      105 k
 dwz                       x86_64      0.12-11.fc31          fedora       107 k
 efi-srpm-macros           noarch      4-3.fc31              fedora        22 k
 fonts-srpm-macros         noarch      2.0.3-1.fc31          updates       26 k
 fpc-srpm-macros           noarch      1.2-2.fc31            fedora       7.6 k
 ghc-srpm-macros           noarch      1.5.0-1.fc31          fedora       7.6 k
 gnat-srpm-macros          noarch      4-10.fc31             fedora       8.2 k
 go-srpm-macros            noarch      3.0.8-4.fc31          fedora        25 k
 golang-bin                x86_64      1.13.14-1.fc31        updates       78 M
 golang-src                noarch      1.13.14-1.fc31        updates      6.5 M
 nim-srpm-macros           noarch      3-1.fc31              updates      8.2 k
 ocaml-srpm-macros         noarch      5-6.fc31              fedora       7.8 k
 openblas-srpm-macros      noarch      2-6.fc31              fedora       7.3 k
 perl-srpm-macros          noarch      1-33.fc31             fedora       8.2 k
 python-srpm-macros        noarch      3-57.fc31             updates       17 k
 qt5-srpm-macros           noarch      5.13.2-1.fc31         updates      8.8 k
 redhat-rpm-config         noarch      143-1.fc31            updates       62 k
 rust-srpm-macros          noarch      14-1.fc31             updates      9.6 k
Installing weak dependencies:
 mercurial                 x86_64      4.9-2.fc31            fedora       4.8 M

Transaction Summary
================================================================================
Install  22 Packages

Total download size: 118 M
Installed size: 421 M
Is this ok [y/N]: y

准备测试源码

main.go

package main

import "fmt"

func main()  {
	fmt.Printf("hello\n");
}

编译并运行

[yeqiang@localhost tmp]$ go build main.go
[yeqiang@localhost tmp]$ ll | grep main
-rwxrwxr-x. 1 yeqiang yeqiang 2025440 2020-08-11 16:52:25 main
-rw-rw-r--. 1 yeqiang yeqiang      68 2020-08-11 16:42:23 main.go
[yeqiang@localhost tmp]$ ./main
hello

查看输出文件信息

[yeqiang@localhost tmp]$ file main
main: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=EnLB0Ikh-wU10o2tVRQy/ytA0vdl4T0BEp4FtWqO2/eER7mW9n9u_2Bo8hi8SU/_FTIjAEkg0f25jqy_anV, not stripped

这是一个静态编译出来的可执行文件

 类似资料: