Unable to install Go packages in Macbook with M1 chip - go

When I ran the command "go install github.com/go-delve/delve/cmd/dlv" in the delve folder, after downloading go-delve in my go path, the terminal showed the following result:
"go install github.com/go-delve/delve/cmd/dlv: mkdir /Desktop: read-only file system"
Terminal result put here
When I googled the same, I came across a website(https://www.dev2qa.com/how-to-fix-read-only-file-system-error-when-run-mkdir-command-on-macos/) which requires me to disable System Integrity Protection on my MacBook and it asks me to hold the option key or command + R immediately after Mac chimes in reboot after starting the MacBook, until I see a boot in a "console/terminal" mode.. But nothing happened when I tried doing that.
I am not knowing what to do. Please guide me through the right way to install dlv and other packages of go successfully on my Macbook.

make sure you use the right go version (1.16 or later, arm64)
$ go version
go version go1.17.1 darwin/arm64
make sure the env is right by this command
$ go env
check GOROOT GOPATH GOARCH GOBIN
try to install it directly
$ go install github.com/go-delve/delve/cmd/dlv#latest
your error occurs because you have no permission of /Desktop, and i'm sure install dlv don't need something like this, it will install to ~/go/bin

Related

vim-go: could not find 'gopls'

After installing Plug 'fatih/vim-go' Plugin for golang i get few errors
steps:
When opening .go file with vim I get a error:
vim-go: could not find 'gopls' . Run :GoInstallBinaries to fix it
vim-go: could not determine appropriate working directory for go plus
When doing :GoInstallBinaries I get more errors like:
vim-go: guru not found. instaling golang.org..guru#master to folder C:\Users\*MYPC*\go\bin\
vim-go: Error instaling golang.org/x/tools/cmdfuru#master: The system cannot find the path specified.
vim-go: goplus not found. instaling golang.org..goplus#latest to folder C:\Users\*MYPC*\go\bin\
vim-go: Error instaling golang.org..goplus#latest: The system cannot find the path specified.
.
.
.
it does that 8 more times with godef,motion,errcheck,dlv,iferr,golint...
When i do :echo $PATH in Vim i have C:\Users*MYPC*\go\bin\
I am running gvim on Windows 10
golang in cmd or powershell work fine...
Just run go get golang.org/x/tools/gopls#latest, and problem solved!
Answer for WSL (Windows subsystem for Linux):
I tried to installed gopls manually, running go get golang.org/x/tools/gopls#latest but I was getting the following error:
XXXX#XXXX:~$ go get golang.org/x/tools/gopls#latest
go: can only use path#version syntax with 'go get' and 'go install' in module-aware mode
Changing the Go mode fixed the problem at this stage GO111MODULE=on, then I could run
go install golang.org/x/tools/gopls#latest
However, later on, when vim-go was trying to install the missing packages after running GoInstallBinaries I was getting errors that I couldn't use versions with go install. So what I did was reinstall Go (the latest version) on the system using these instructions. After doing that, vim-go was able to install the packages. I hope this answer saves time for future vim-go enthusiasts.
for mac was solved with
brew install gopls
In the vim-go setup instructions, there's a detail about running :GoInstallBinaries in vim after install. You probably missed it (I ran into this issue after I upgraded to a new go runtime)

command 'go.tools.install' not found

I am trying to install Go tools in my VS Code editor and when I select the View, CMD, Install and select Go: Install/Update tools, I get this -> "command 'go.tools.install' not found"
What am I doing wrong?
As seen in Microsoft/vscode-go issue 755:
For all guys who are stuck with command 'go.tools.install' not found problem on Windows.
Check if %GOPATH%\bin is in your PATH environment variable.
After half and an hour I finally figured out that PATH remains unchanged if you try to change it like set PATH=%PATH%.... You need explicitly change it in your system settings.
With recent Go installation, make sure GOROOT reference your Go installation folder.
I also like to set go.goroot to that folder in the settings of VSCode.
You don't need GOPATH: it defaults to %USERPROFILE%\go: make sure %USERPROFILE%\go\bin is in your PATH, before launching VSCode.
unzip go1.13.6.windows-amd64.zip anywhere (not in %USERPROFILE%\go, since it is reserved for GOPATH)
set GOROOT to C:\path\to\go (where you just uncompressed the Go archive)
add %GOROOT%\bin to %PATH%
In my case I was on Ubuntu and installed go using snap so I did the following:
Uninstall go from snap
sudo snap remove go
Download go from the original source: https://go.dev/doc/install
Install go as recommended in the source e.g.:
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.1.linux-amd64.tar.gz
Run the following to add the environment variables in the .bashrc:
echo export GOROOT=/usr/local/go >> ~/.bashrc
echo export GOPATH=\$HOME/go >> ~/.bashrc
echo export PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin >> ~/.bashrc
Note: Setting $GOROOT variable is obsolete in recent versions as discussed here
Restart the VS Code to read the environment variables set above
In VSCode press Ctrl+Shift+P and run again the GO: Install/Update tools, install everything selecting the checkboxes and you are good to GO!
In my case Go language was not installed so this command was not working from VS Code. Consider downloading and installing latest version of go language from https://go.dev/dl/
After I installed version 1.19.3 of go to my Windows 11 x64, the "go: install/Update Tools" command worked fine without any changes needed to be done to eviroment variables (PATH,GOROOT).(all changes were done by installer)
BTW restart of VSCODE really helps to make it work after installation of go.

Install snap on Ubuntu Precise

After a purchase of ARK-20-S8A11E, i find out that it only supports ubuntu 12.04 and that network manager uses snap which only availale on ubuntu 14 onward. I need Mobilemanager to collect information of an LTE module integrated in the PC.
For that, i tried to install snap from source.
I needed "go", and with apt-get install golang, the last version installed on precise is go1. and snap uses go1.6 onward version.
Therefore, i installed the latest version of go from sources. It is well installed, the output of go --version is : go version go1.11.4 linux/amd, and tested a basid hello.go.
I followed this link for snap installation: https://github.com/snapcore/snapd/blob/master/HACKING.mdsnap.
The build command " sudo -E go build -o /tmp/snap github.com/snapcore/snapd/cmd/snap" give an output as the "go command not found".
The GOPATH and PATH are well verified, the go env also.
Could you please help me sort this issue?
Thank you,
sudo is the troublemaker here. When sudoing the $PATH env var is replaced with the secure_path from /etc/sudoers (see this and this.)
Either do not run go as sudo, add the go path to the secure_path or include the full path to go in your command (sudo -E /usr/local/bin/go build -o /tmp/snap github.com/snapcore/snapd/cmd/snap)

Removed golang but go command still works?

I'm running Mac OSX Yosemite.
I'm trying update from golang 1.4 to golang 1.6. I uninstalled golang but I noticed I could still run the go command go version = go1.4.2 darwin/amd64. Why is this so?
The directions aren't super clear IMO. They say
To remove an existing Go installation This is usually /usr/local/go
(done) Remove etc/paths.d/go
I edited the bash by running go version go1.4.2 darwin/amd64
I was running into the same issue. I ended up with this solution:
cd /usr/local/bin
rm go
Removes the 'go' command
Then go back to golang.org and re-download the newest version, run the installer and when you run the 'go' command it will display 1.12.9 (As of writing this post).
You can try this
sudo apt-get remove golang-go
Then do this
sudo apt-get remove --auto-remove golang-go
I ran source ~/.bash_profile and that updated the env variables.

`go get` fails with permission denied on certain go packages

Installing some go packages fails with permission denied error, eg.:
$ go get code.google.com/p/go.tools/cmd/cover
go install code.google.com/p/go.tools/cmd/cover: open /usr/local/go/pkg/tool/darwin_amd64/cover: permission denied
When I tried using sudo to fix the permission issue, it failed with $GOPATH not set error:
$ sudo go get code.google.com/p/go.tools/cmd/cover
Password:
package code.google.com/p/go.tools/cmd/cover: cannot download, $GOPATH not set. For more details see: go help gopath
How can I solve this?
The godoc, go tool vet, go tool cover etc. are special go.tools commands that are meant to be installed into the system path by default with the go binary. If these commands are not available, you should try reinstall go itself (or find go.tools in your packaging system).
Note: On OS X 10.8+, try installing go using Homebrew instead of the official .pkg installer and your troubles should be gone (as of go 1.4): brew install go
If you want to download a specific pkg into your $GOPATH (eg. 3rd party dependency), use go get -d <pkg> instead. Example:
go get -d code.google.com/p/go.tools/cmd/cover
You shouldn't need to use the sudo hammer at all, as your $GOPATH should point to a directory that you own, and thus no permission: denied error at all.
But if you really know what you're doing, and you still want to sudo install something, you need to edit the sudoers file first to fix the root's GOPATH:
$ sudo visudo
add the following line:
Defaults env_keep += "GOPATH"
This will make the sudo go get (root context) pick up your $GOPATH value.
I just ran into this because I installed go with MacPorts. Vojtech Vitek's answer pointed me in the right direction but I thought I would go ahead and post the literal solution I needed.
Run sudo port install go-tools. I don't know why godoc et al are not included with the base go package, but whatever.

Resources