How to install Golang on chrome os

huangapple go评论94阅读模式
英文:

How to install Golang on chrome os

问题

我尝试了来自https://go.dev/doc/install的方法,但是一直出现"-bash: go: command not found"的错误。
我尝试了https://gist.github.com/conoro/4fca191fad018b6e47922a21fab499ca,但是当我到达"Use sftp or scp on the ARM64 device to get the tar.gz file"阶段时,我不知道要运行什么命令。有人可以帮忙吗?

英文:

I tried the method from https://go.dev/doc/install and I keep getting "-bash: go: command not found".
I tried https://gist.github.com/conoro/4fca191fad018b6e47922a21fab499ca but I dont know what command to run when I get to the "Use sftp or scp on the ARM64 device to get the tar.gz file" stage. Any help???

答案1

得分: 0

你不需要在开发者模式下从源代码编译,你可以直接使用Chromebrew提供的版本。

如果你的Chromebook相对较新,你可以启用ChromeOS内置的Linux虚拟机,以在不开启开发者模式的情况下安装Go。按照以下Google支持文章中的步骤启用此功能:https://support.google.com/chromebook/answer/9145439。这已经在版本71.0.3578.127的三星Chromebook Plus上进行了测试。如果你无法使用此功能,你将需要启用开发者模式。

本教程将向你展示如何在Chrome OS上安装、构建和运行Go。请注意,这仅在64GB LTE Pixel上进行了测试,但应该也适用于其他Chromebook。请注意,启用开发者模式会降低Chrome OS提供的安全保证。

安装Go

首先从Go下载页面下载Linux的最新版本。然后,通过按下(Ctrl+Alt+T)打开一个shell,并输入shell,然后按回车键来打开一个shell。然后使用以下命令解压缩它(将<Go Linux package>替换为你下载的文件的名称):

sudo tar xpvf ~/Downloads/<Go Linux package> -C /usr/local

Go现在应该已经安装好了,你可以通过输入/usr/local/go/bin/go来测试。如果安装正确,你应该看到Go的帮助提示。Go现在已经安装好了。

创建工作空间

为了保持简单,只需创建一个名为/usr/local/go/work的文件夹。此外,在/usr/local/go/work/内创建一个名为src的文件夹。

设置路径

将以下内容添加到~/.bashrc文件中:

export GOPATH="/usr/local/go/work"
export PATH="${PATH}:/usr/local/go/bin:${GOPATH}/bin"

这将允许你在shell中运行Go程序。

测试是否成功

首先,在/usr/local/go/src文件夹内创建一个文件夹。然后,在该文件夹中创建一个名为hello.go的文件,并将以下内容添加到其中:

package main

import "fmt"

func main() {
	fmt.Println("Hello, Chrome OS!")
}

现在,运行go install hello。然后,运行${GOPATH}/bin/hello(或者如果你在上面设置了GOPATH,只需运行hello),你应该看到Hello, Chrome OS!


来源:https://github.com/golang/go/wiki/ChromeOS

英文:

You don't need to compile from source in Developer mode, you can just use the Chromebrew-provided version.

If your Chromebook is relatively new, you can enable the Linux VM now built into ChromeOS to install Go without developer mode. Follow the steps from the following Google Support article to enable this feature- https://support.google.com/chromebook/answer/9145439. This has been tested on a Samsung Chromebook Plus on version 71.0.3578.127. If this feature is not available for you, you will need to enable Developer Mode.

This tutorial will show you how to install, build, and run Go on Chrome OS.
Please note this has only been tested on a 64GB LTE Pixel, however it should work on other Chromebooks. Note that enabling developer mode reduces the security guarantees offered by Chrome OS.

Install Go

First download the latest version of Go for Linux from the Go Downloads page.
After that, open a shell by hitting (CTRL+ALT+T) and typing in shell then hit enter. Then extract it using the following command (when replacing &lt; Go Linux package &gt; with the name of the file you downloaded):

sudo tar xpvf ~/Downloads/&lt; Go Linux package &gt; -C /usr/local

Go should now be installed you can test this by typing /usr/local/go/bin/go. If it installed correctly, you should see the Go help prompt. Go is now installed.

Create a Workspace

To keep this simple just create a folder called /usr/local/go/work. Also, create a folder called src inside /usr/local/go/work/.

Set PATH

Add the following to ~/.bashrc:

export GOPATH=&quot;/usr/local/go/work&quot;
export PATH=&quot;${PATH}:/usr/local/go/bin:${GOPATH}/bin&quot;

This will allow you to run your Go programs in your shell.

Test if it worked

First create a folder inside of your /usr/local/go/src folder. After that create a file in your folder called hello.go with the following in it:

package main

import &quot;fmt&quot;

func main() {
	fmt.Println(&quot;Hello, Chrome OS!&quot;)
}

Now, run go install hello. Then, run ${GOPATH}/bin/hello (or just hello if you setup your GOPATH above) and you should see Hello, Chrome OS!.


Collected from : https://github.com/golang/go/wiki/ChromeOS

答案2

得分: 0

如果你想在开发模式下在Chromebook上下载Go,而不安装Linux,请按照以下步骤操作:

  1. 如果还没有启用开发模式,请先启用开发模式。
  2. 在终端中下载最新版本的Linux版Go(https://go.dev/dl/)。

在你的终端中

输入Shell

mkdir ~/Coding
tar -xzf ~/Downloads/在这里添加你的版本 -C ~/Coding/
echo "sudo mount -i -o remount,exec /home/chronos/user/" >> ~/.bash_profile
echo "sudo mount -i -o remount,exec /tmp/" >> ~/.bash_profile

设置环境变量

export GOROOT=~/CS/go *你提取Go的位置*
export GOPATH=~/Downloads/go *你想保存Go项目的位置*
PATH=$PATH:$GOROOT/bin:$GOPATH/bin *这将把所有内容添加到PATH中*

为了确保一切正常工作,请重新启动终端并输入go version,你应该看到你安装的版本

英文:

If you want to download Go on a Chromebook in Dev Mode, without installing Linux follow these steps:

  1. Enable Dev mode, in case you have not already.
  2. Download the latest version of Go for Linux (https://go.dev/dl/)

IN YOUR TERMINAL

Type Shell

mkdir ~/Coding
tar -xzf ~/Downloads/ADD YOUR VERSION HERE -C ~/Coding/  
echo &quot;sudo mount -i -o remount,exec /home/chronos/user/&quot; &gt;&gt; ~/.bash_profile
echo &quot;sudo mount -i -o remount,exec /tmp/&quot; &gt;&gt; ~/.bash_profile

SET ENV VARIABLES

export GOROOT=~/CS/go *Where you extracted Go*
export GOPATH=~/Downloads/go *Where you wanna keep your Go projects*
PATH=$PATH:$GOROOT/bin:$GOPATH/bin *This adds everything to PATH*

To make sure everything works restart your Terminal and type go version you should see the version you installed

huangapple
  • 本文由 发表于 2022年6月26日 18:47:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/72760899.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定