jetbrainsgoland配置go开发环境
⽂章⽬录
安装go编译器
1. 下载go编译器源码包,Linux直接下载源码包
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
4. 创建go⼯作⽬录
cd ~
mkdir GOPATH
cd AOPATH
mkdir src bin
5. 将/usr/local/go/bin⽬录添加到PATH环境变量大尺度美剧推荐
关于环境变量配置可参考这篇⽂章,时间久了容易忘记环境变量的配置,索性留个链接⽅便以后查看。
在~/.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
6. 查看环境变量是否导⼊
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"
7. 测试是否安装成功,打开终端,输⼊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 an
d C
cache      build and test caching
environment environment variables
filetype    file types
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.
8. 创建第⼀个go程序
创建⼀个.go后缀的⽂件,输⼊以下代码
der@SA:~$
package main
import"fmt"
func main(){
fmt.Println("Hello, World!")
}
9. 运⾏第⼀个go程序
der@SA:~$ go
Hello, World!
安装jetbrains-goland
1. 去jetbrains官⽹下载jetbrains-goland
2. 解压jetbrains-goland到⽤户家⽬录下
3. 进⼊解压⽬录下的/bin⽬录,运⾏golang.sh⽂件./goland.sh
4. 选择试⽤⼀个⽉
5. 新建⼀个⽂件林志颖和谁结婚了
6. 输⼊hello-world程序
package main
import"fmt"
func main(){
fmt.Println("Hello, World!")
}
7. 右键运⾏⽂件,第⼀次运⾏会提⽰输⼊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