教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 jetbrains goland配置go开发环境

jetbrains goland配置go开发环境

发布时间:2021-05-26   编辑:jiaochengji.com
教程集为您提供jetbrains goland配置go开发环境等资源,欢迎您收藏本站,我们将为您提供最新的jetbrains goland配置go开发环境资源

文章目录

  • 安装go编译器
  • 安装jetbrains-goland
    • 创建快捷方式

安装go编译器

  1. 下载go编译器源码包,Linux直接下载源码包
    go编译器下载地址

  2. 解压源码包得到一个以go命名的源码包文件夹

  3. 将源码包移动到/usr/local/目录下

der@SA:/usr/local$ pwd
/usr/local
der@SA:/usr/local$ ls -l |grep go
drwxr-xr-x 10 der  der  4096 7月  17 06:30 go
  1. 创建go工作目录
cd ~
mkdir GOPATH
cd AOPATH
mkdir src bin
  1. /usr/local/go/bin目录添加到PATH环境变量中

关于环境变量配置可参考这篇文章Linux环境变量设置,时间久了容易忘记环境变量的配置,索性留个链接方便以后查看。

~/.bashrc文件和/etc/profile文件追加以下内容,并使用source命令使其生效source /etc/profile&source ~/.bashrc

export GOROOT=/usr/local/go #GOROOT是系统上安装Go软件包的位置。
export GOPATH=/home/limeng/GOPATH #GOPATH是工作目录的位置。
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
  1. 查看环境变量是否导入
der@SA:/usr/local$ export |grep GO
declare -x GOPATH="/home/der/GOPATH"
declare -x GOROOT="/usr/local/go"
declare -x PATH="/home/der/GOPATH/bin:/usr/local/go/bin:/home/limeng/GOPATH/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
  1. 测试是否安装成功,打开终端,输入go,有输出则安装成功
der@SA:~$ go
Go is a tool for managing Go source code.

Usage:

	go <command> [arguments]

The commands are:

	bug         start a bug report
	build       compile packages and dependencies
	clean       remove object files and cached files
	doc         show documentation for package or symbol
	env         print Go environment information
	fix         update packages to use new APIs
	fmt         gofmt (reformat) package sources
	generate    generate Go files by processing source
	get         add dependencies to current module and install them
	install     compile and install packages and dependencies
	list        list packages or modules
	mod         module maintenance
	run         compile and run Go program
	test        test packages
	tool        run specified go tool
	version     print Go version
	vet         report likely mistakes in packages

Use "go help <command>" for more information about a command.

Additional help topics:

	buildmode   build modes
	c           calling between Go and C
	cache       build and test caching
	environment environment variables
	filetype    file types
	go.mod      the go.mod file
	gopath      GOPATH environment variable
	gopath-get  legacy GOPATH go get
	goproxy     module proxy protocol
	importpath  import path syntax
	modules     modules, module versions, and more
	module-get  module-aware go get
	module-auth module authentication using go.sum
	module-private module configuration for non-public modules
	packages    package lists and patterns
	testflag    testing flags
	testfunc    testing functions

Use "go help <topic>" for more information about that topic.
  1. 创建第一个go程序

创建一个.go后缀的文件,输入以下代码

der@SA:~$ cat hello.go 
package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
  1. 运行第一个go程序
der@SA:~$ go run hello.go 
Hello, World!

安装jetbrains-goland

  1. 去jetbrains官网下载jetbrains-goland
  2. 解压jetbrains-goland到用户家目录下
  3. 进入解压目录下的/bin目录,运行golang.sh文件./goland.sh
  4. 选择试用一个月
  5. 新建一个hello.go文件
  6. 输入hello-world程序
package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
  1. 右键运行hello.go文件,第一次运行会提示输入go编译器的目录,选择/usr/local/go目录即可

创建快捷方式

创建一个桌面快捷方式文件/usr/share/applications/Goland.desktop,并将/usr/share/applications/Goland.desktop这个文件复制一份到桌面,双击桌面的Goland.desktop文件运行,完成桌面快捷方式的创建

der@SA:~$ cat /usr/share/applications/Goland.desktop 
[Desktop Entry]
Name=Goland
Comment=Goland IDE
Exec=/home/der/GoLand-2020.1.4/bin/goland.sh #goland的执行路径
Icon=/home/der/GoLand-2020.1.4/bin/goland.png #goland的图标路径
Type=Application
Terminal=false
Encoding=UTF-8
到此这篇关于“jetbrains goland配置go开发环境”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
jetbrains goland配置go开发环境
聊聊,如何快速搭建部署GO开发环境和部署服务?
Go语言学习笔记(1):Golang的安装和配置教程、Goland的安装和破解
Golang Goland 的安装
GOLANG环境安装
查看go 安装了哪些包_go语言基础入门(一)
golang ide 环境搭建_Go语言环境搭建详解(2020版)
go 项目 cmd目录_Go语言基础(一)
os.create指定路径 golang_Go语言(Golang)环境搭建详解
Golang 编辑器

[关闭]
~ ~