安装方法:1、去go官网下载Golang安装包;2、使用cd命名进入安装目录,使用tar命令解压安装包并安装;3、修改“/etc/profile”或“etc/environment”文件,添加“/usr/local/go/bin”文本;4、用sudo命令赋予权限;5、执行“go env -w GOPROXY=https://goproxy.cn,direct”命令修改代理即可。
本教程操作环境:Ubuntu 20.04系统、GO 1.16.4版、DELL G3电脑
环境说明
操作系统: Ubuntu 20.04
Golang: v1.16.4
Golang基础环境
下载地址:https://golang.google.cn/dl/
cd /home/XXX/download # 导航到文件位置,根据自己的情况选定 # 将gox.x.x替换为相应的版本号,比如go1.16.4 tar -C /usr/local -xzf gox.x.x.linux-amd64.tar.gz
两种方法:
- 修改
/etc/profile
文件,在文件最后添加
PATH=$PATH:/usr/local/go/bin
修改
etc/environment
文件,在PATH=
后面的字符串中添加:/usr/local/go/bin
重启系统,检查环境变量是否设置成功
echo $PATH
sudo chmod +x /usr/local/go/bin
go env -w GOPROXY=https://goproxy.cn,direct # 修改代理 go env # 查看修改结果
go version
- 新建项目文件夹
cd /usr/local mkdir code cd code mkdir hello cd hello
- 给code文件夹添加权限
# code文件夹及其子文件夹全部具有权限 sudo chmod -R 777 /usr/local/code
- 新建并编辑程序文件
sudo vim hello.go
- 编辑hello.go程序文件
package main import "fmt" func main(){ fmt.Println("Hello World !") }
编辑完成后保存并关闭文件
- 编译运行
go mod init hello # 初始化go mod go build . # 编译 ./hello # 运行编译后的二进制文件
IDE环境(此处用VSCode)
访问Visual Studio Code官网,可以直接下载
解压到指定文件夹(<span style="font-size: 18px;">/usr/local</span>
)
sudo tar -xzvf code-stable-code_x64-1620838810.tar.gz -C /usr/local
cd /usr/local
sudo chmod +x /usr/local/VSCode-linux-x64/code
复制一个VScode图标文件到 /usr/share/icons/ 目录(后面会有用)
sudo cp /usr/local/VSCode-linux-x64/resources/app/resources/linux/code.png /usr/share/icons/
创建启动器, 在<span style="font-size: 18px;">/usr/share/applications/</span>
目录
sudo vim /usr/share/applications/VSCode.desktop
在文件中输入如下内容,保存后退出
[Desktop Entry] Name=Visual Studio Code Comment=Multi-platform code editor for Linux Exec=/usr/local/VSCode-linux-x64/code Icon=/usr/share/icons/code.png Type=Application StartupNotify=true Categories=TextEditor;Development;Utility; MimeType=text/plain;
开始菜单中已经有了VSCode的图标了
打开go项目的时候会提示安装gopls
,点击install all
以上是ubuntu怎么安装golang的详细内容。更多信息请关注PHP中文网其他相关文章!

theEncoding/binarypackageingoisessential forhandlingbinarydata,offeringFunctionStoreadAndWritedAtainBig-Endianandlittle-endianFormats.1)IT'SidealFornetwork-work-workprotocels,enableSeringSeringSerializationalializationalialization andDeSerialization andDeSerializationOfStructuredDatalizedDataliakePackackEtheadErloth

theessentionfunctionsingo'sbytespackageThatyOuneedToknoware:1)字节.indexforsearchingwithinbyteslices,2)bytes.splitforparsing数据,3)字节。joinforConcatenatingslices,4)bytes.containsforcheckingsubslicepresence和5)bytes.replaceallfordatatatatransformatio

Gooffersalternativestothestringspackageforstringmanipulation:1)Theregexppackageforcomplexpatternmatching,2)Thestrconvpackagefornumericconversions,and3)Externallibrarieslikestrutilforspecializedoperations.Theseoptionscatertodifferentneeds,enhancingyou

效率地使用/binarypackageforhandlingvariousdatatypes,lofterTheSesteps:1)指定bytedorder(例如,binary.littleendian)for -compatibility.2)Usepututuint32/uint322222222222forintegerSandfloat32bits/floatt32bits/floatth322222222frollombitsss.3222frollombitss.3)

掌握bytes包的原因是它能显着提高处理字节切片的效率和性能。 1)bytes包提供了强大的工具,如bytes.Contains用于搜索字节序列,2)bytes.Buffer类型适用于增量构建字节切片,3)了解bytes包的使用陷阱和性能优化策略,如重用bytes.Buffer实例,可以避免常见错误并提升效率。

Go的"strings"包提供了丰富的功能,使字符串操作高效且简单。1)使用strings.Contains()检查子串。2)strings.Split()可用于解析数据,但需谨慎使用以避免性能问题。3)strings.Join()适用于格式化字符串,但对小数据集,循环使用 =更有效。4)对于大字符串,使用strings.Builder构建字符串更高效。

Go语言使用"strings"包进行字符串操作。1)拼接字符串使用strings.Join函数。2)查找子串使用strings.Contains函数。3)替换字符串使用strings.Replace函数,这些函数高效且易用,适用于各种字符串处理任务。

资助bytespackageingoisesential foreffited byteSemanipulation,uperingFunctionsLikeContains,index,andReplaceForsearchingangingAndModifyingBinaryData.itenHancesperformanceNandCoderAceAnibility,MakeitiTavitalToolToolToolToolToolToolToolToolToolForhandLingBinaryData,networkProtocols,networkProtocoLss,networkProtocols,andetFilei


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

记事本++7.3.1
好用且免费的代码编辑器

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境