安装Go语言到树莓派上以便使用GitHub项目。

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

Install Go Raspberry pi for Github project

问题

你好,我会为你翻译以下内容:

嗨,我在2018年从Github.talkiepi安装了talkiepi,并且安装和使用都很顺利。
但是在2021年,我安装了最新版本的Stretch,并按照步骤进行操作,但遇到了一个错误。

当我执行go get github.com/dchote/gopus时,出现以下错误:
package math/bits: 无法识别的导入路径"math/bits"(导入路径不以主机名开头)

我在网上搜索并阅读了其他帖子,有些人说这是因为Go版本1.7的原因。

我的问题是,当我执行apt-get install golang libopenal-dev libopus-dev git时,唯一的选择是版本1.7。

我尝试手动安装较新版本,使用以下命令:

wget https://dl.google.com/go/go1.14.4.linux-armv6l.tar.gz
sudo tar -C /usr/local -xzf go1.14.4.linux-armv6l.tar.gz
rm go1.14.4.linux-arm64.tar.gz

步骤3:配置Go

现在你只需要配置它,这是任何Go安装都必须做的。

打开你的~/.profile文件(使用nano、vi等编辑器)

vi ~/.profile

PATH=$PATH:/usr/local/go/bin
GOPATH=$HOME/go

但是我无法让它与github talkiepi一起工作。

在树莓派上以root身份(sudo -i)安装golang和其他所需的依赖项,然后构建talkiepi:

apt-get install golang libopenal-dev libopus-dev g
su mumble
mkdir ~/gocode
mkdir ~/bin
export GOPATH=/home/mumble/gocode
export GOBIN=/home/mumble/bin

cd $GOPATH

go get github.com/dchote/gopus
go get github.com/dchote/talkiepi

cd $GOPATH/src/github.com/dchote/talkiepi

go build -o /home/mumble/bin/talkiepi cmd/talkiepi/main.go

最新测试

    wget https://dl.google.com/go/go1.17.linux-armv6l.tar.gz
    
    rm -rf /usr/local/go && tar -C /usr/local -xzf go1.17.linux-armv6l.tar.gz

export PATH=$PATH:/usr/local/go/bin

它安装在usr/local目录下

mumble@raspberrypi:/root $ mkdir ~/gocode
mumble@raspberrypi:/root $ mkdir ~/bin
mumble@raspberrypi:/root $ export GOPATH=/home/mumble/gocode
mumble@raspberrypi:/root $ export GOBIN=/home/mumble/bin
mumble@raspberrypi:/root $ cd $GOPATH
mumble@raspberrypi:~/gocode $ go get github.com/dchote/gopus
bash: go: command not found
mumble@raspberrypi:~/gocode $ go install github.com/dchote/talkiepi/cmd/talkiepi@latest
bash: go: command not found

==================================Friday 03/08/2021=================
所以我重新安装了树莓派的Stratch Os
进行了完整的更新,然后重新启动。我安装了最新的go go1.17.linux-armv6l.tar.gz。

使用这个链接安装go

nano go_installer.sh

输入以下shell脚本并保存文件。

export GOLANG="$(curl https://golang.org/dl/|grep linux-armv6l|grep -v beta|head -1|awk -F\> {'print $3'}|awk -F\< {'print $1'})"
wget https://golang.org/dl/$GOLANG
sudo tar -C /usr/local -xzf $GOLANG
rm $GOLANG
unset GOLANG

接下来使脚本可执行:

sudo chmod +x go_installer.sh

要运行shell脚本,请输入:

./go_installer.sh

最后一步-设置路径

nano ~/.profile

滚动到文件的末尾,添加以下内容:

PATH=$PATH:/usr/local/go/bin
GOPATH=$HOME/golang

source ~/.profile

pi@raspberrypi:~ $ which go
/usr/local/go/bin/go

pi@raspberrypi:~ $ go version
go version go1.17 linux/arm

现在安装Talkiepi

pi@raspberrypi:~ $ sudo -i
root@raspberrypi:~# adduser --disabled-password --disabled-login --gecos "" mumble

root@raspberrypi:~# usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input,gpio mumble

root@raspberrypi:~# apt-get install libopenal-dev libopus-dev git

Do you want to continue? [Y/n] y

root@raspberrypi:~# su mumble
mumble@raspberrypi:/root $ export GOPATH=/home/mumble/gocode
mumble@raspberrypi:/root $ export GOBIN=/home/mumble/bin
mumble@raspberrypi:/root $ cd $GOPATH
bash: cd: /home/mumble/gocode: No such file or directory

所以Go不在正确的目录中,我该如何移动它。

英文:

Hi so installed talkiepi from Github.talkiepi in 2018 installed and worked fine.
In 2021 iv installed latest version of Stretch and followed the steps but hit into an error.

When i do go get github.com/dchote/gopus I get the following error.
package math/bits: unrecognized import path "math/bits" (import path does not begin with hostname)

I been searching on line and going true other posts about this issue and some people are saying it because of Go version 1.7

my issue is when i do apt-get install golang libopenal-dev libopus-dev git
My only option is version 1.7

Iv tried to manualy install later versions using the following.

wget https://dl.google.com/go/go1.14.4.linux-armv6l.tar.gz
sudo tar -C /usr/local -xzf go1.14.4.linux-armv6l.tar.gz
rm go1.14.4.linux-arm64.tar.gz

Step 3: Configure Go

Now you just need to configure it, which you have to do with any Go installation anyway.

Open up your ~/.profile (Using nano, vi, etc)

vi ~/.profile

PATH=$PATH:/usr/local/go/bin
GOPATH=$HOME/go

But i cant get it to work with the github talkiepi

As root on your Raspberry Pi (sudo -i), install golang and other required dependencies, then build talkiepi:

apt-get install golang libopenal-dev libopus-dev g
su mumble
mkdir ~/gocode
mkdir ~/bin
export GOPATH=/home/mumble/gocode
export GOBIN=/home/mumble/bin

cd $GOPATH

go get github.com/dchote/gopus
go get github.com/dchote/talkiepi

cd $GOPATH/src/github.com/dchote/talkiepi

go build -o /home/mumble/bin/talkiepi cmd/talkiepi/main.go

NEWTESTS

    wget https://dl.google.com/go/go1.17.linux-armv6l.tar.gz
    
    rm -rf /usr/local/go && tar -C /usr/local -xzf go1.17.linux-armv6l.tar.gz

export PATH=$PATH:/usr/local/go/bin

its installed in usr/local

mumble@raspberrypi:/root $ mkdir ~/gocode
mumble@raspberrypi:/root $ mkdir ~/bin
mumble@raspberrypi:/root $ export GOPATH=/home/mumble/gocode
mumble@raspberrypi:/root $ export GOBIN=/home/mumble/bin
mumble@raspberrypi:/root $ cd $GOPATH
mumble@raspberrypi:~/gocode $ go get github.com/dchote/gopus
bash: go: command not found
mumble@raspberrypi:~/gocode $ go install github.com/dchote/talkiepi/cmd/talkiepi@latest
bash: go: command not found

==================================Friday 03/08/2021=================
So i went with a fresh install of Stratch Os for the Raspberry pi
did a full update and then a reboot. I have installed the latest go go1.17.linux-armv6l.tar.gz.

Install go using this links

nano go_installer.sh

enter the following shell scripts and save the file.

export GOLANG="$(curl https://golang.org/dl/|grep linux-armv6l|grep -v beta|head -1|awk -F\> {'print $3'}|awk -F\< {'print $1'})"
wget https://golang.org/dl/$GOLANG
sudo tar -C /usr/local -xzf $GOLANG
rm $GOLANG
unset GOLANG

Next make the script executable:

sudo chmod +x go_installer.sh

To run the shell script, type:

./go_installer.sh

Final Step - Setup path

nano ~/.profile

Scroll all the way down to the end of the file and add the following:

PATH=$PATH:/usr/local/go/bin
GOPATH=$HOME/golang

source ~/.profile

pi@raspberrypi:~ $ which go
/usr/local/go/bin/go

pi@raspberrypi:~ $ go version
go version go1.17 linux/arm

Now to install Talkiepi

pi@raspberrypi:~ $ sudo -i
root@raspberrypi:~# adduser --disabled-password --disabled-login --gecos "" mumble

root@raspberrypi:~# usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input,gpio mumble

root@raspberrypi:~# apt-get install libopenal-dev libopus-dev git

Do you want to continue? [Y/n] y

root@raspberrypi:~# su mumble
mumble@raspberrypi:/root $ export GOPATH=/home/mumble/gocode
mumble@raspberrypi:/root $ export GOBIN=/home/mumble/bin
mumble@raspberrypi:/root $ cd $GOPATH
bash: cd: /home/mumble/gocode: No such file or directory

SO Go not in the correct directory how can i move it.
1: https://github.com/dchote/talkiepi/blob/master/doc/README.md
2: https://www.e-tinkers.com/2019/06/better-way-to-install-golang-go-on-raspberry-pi/

答案1

得分: 1

Go项目仅支持最近的两个主要版本。截至今天,最新的版本是Go 1.17和Go 1.16.7。要安装支持的版本,请参阅https://golang.org/doc/install。

请注意,最近的Go版本默认启用模块模式。要在模块模式下安装github.com/dchote/talkiepi/cmd/talkiepi二进制文件(无需定义自己的模块),可以运行以下命令:

$ go install github.com/dchote/talkiepi/cmd/talkiepi@latest

另外,apt-get正在安装Go 1.7表明您的树莓派上的Linux发行版也非常旧。您可能还想查看更新和升级树莓派操作系统

英文:

The Go project supports only the two most recent major Go releases. (As of today, that is Go 1.17 and Go 1.16.7.) To install a supported release, see https://golang.org/doc/install.

Note that recent versions of Go enable module mode by default. To install the github.com/dchote/talkiepi/cmd/talkiepi binary in module mode (without defining your own module), you can run:

$ go install github.com/dchote/talkiepi/cmd/talkiepi@latest

That said, the fact that apt-get is installing Go 1.7 suggests that the Linux distro installation on your Pi is also very old. You may want to also check out Updating and Upgrading Raspberry Pi OS.

huangapple
  • 本文由 发表于 2021年9月2日 05:37:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/69020822.html
匿名

发表评论

匿名网友

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

确定