I am trying to follow along with the following YouTube video on getting started with Go Debugging.
It recommends following the Delve installation instructions on the official Delve github repo. For Mac users, they are as follows:
Making sure the toolchain is in place
xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Using "go get" to install Delve
go get -u github.com/go-delve/delve/cmd/dlv
Making sure developer mode is enabled in Xcode
sudo /usr/sbin/DevToolsSecurity -enable
Developer mode is already enabled.
To check that the installation has been completed correctly, I tried running the following in my Go project directlry:
dlv debug
zsh: command not found: dlv
The author of the video tutorial recommends updating GOPATH and PATH variables in the ~/.bash_profile file in the case that the command is not recognized. I did so so by adding:
export GOPATH=/Users/<user_name>/go/src/
export PATH=$PATH:/Users/<user_name/go/src/my_project
However, even after doing so, I get the same result when trying to run the debugger:
dlv debug
zsh: command not found: dlv
Even if I change the shell for the default zsh to bash, using exec bash, I get the same result.
In order to run an executable, it needs to be available in your PATH.
1. Configure your path.
Make sure that your GOPATH and $GOPATH/bin directories are set correctly in your shell environment. You can do this by adding the following lines to your shell configuration.
~/.zshrc if you're using zsh.
~/.bash_profile if you're using bash.
export GOPATH="$HOME/go"
export PATH="$GOPATH/bin:$PATH"
2. Re-load your shell configuration.
Make sure to either restart your shell or run source on your shell configuration file after the changes:
source ~/.zshrc if you're using zsh.
source ~/.bash_profile if you're using bash.
3. Install the dlv package.
go install github.com/go-delve/delve/cmd/dlv
This is assuming that you're using /Users/<username>/go as your GOPATH.
You should now be able to run dlv from your terminal session.
Good luck!
Set the environment variable GOBIN to be where you want the dlv binary to be installed.
For example:
GOBIN=~/bin go install github.com/go-delve/delve/cmd/dlv
This will install dlv in ~/bin
Clarification
When you run go install, the installation path can be specified by setting the GOBIN environment variable.
There are two ways to set the environment variable:
1) Run export GOBIN=<SOMETHING> before you run go install ..
$ export GOBIN="$HOME/bin"
$ go install github.com/go-delve/delve/cmd/dlv
The export command will alter the environment in the current terminal session. Any later command you execute will see the value you set for GOBIN
When you go with this approach, you usually want to have this environment variable active not only in this session, but all future sessions as well. So it's better to add the line to your bash profile.
2) Set the environment variable only for the command.
$ A=10 some-command
In this case, some-command will see the value of the environment variable A set to '10'. If you run a later command, it will not see this value.
This approach is useful when you are just trying things out, or if you only want to set certain environment variables in certain situations.
The command line I provided as the answer follows this second approach.
It sets the GOBIN variable to the ~/bin directory, and then invokes go install in the same line. This way, this invocation of go install will install dlv in ~/bin
This of course assumes you have a bin directory in your home directory.
If you don't have such directory, then this will not work.
The idea is not to copy paste the line as is. The idea is to change ~/bin to be the directory where you would like the dlv binary to be installed.
Related
Go is already installed in my system.
and path variable is in .bashrc file.
# Golang
export PATH=$PATH:/usr/local/go/bin
$ go version
go version go1.16.14 linux/amd64
Now, I am willing to work with Beego and bee dev tools. For that, I installed Beego and Bee by using these commands.
$ go get -u github.com/beego/beego/v2
$ go get -u github.com/beego/bee/v2
both got successfully installed. but when I am using the command bee version it is resulting this in the Terminal.
Command 'bee' not found, did you mean:
command 'tee' from deb coreutils (8.30-3ubuntu2)
command 'see' from deb mime-support (3.64ubuntu1)
Try: sudo apt install <deb name>
I am a beginner in the programming world. I am not sure How to resolve it. Can Someone help me with this?
I had the same issue. When using the command bee is installed in home/go/bin. What I did was copy the bee file from there and paste it in usr/local/go/bin. Also I used go install instead of go get and at the end of the url I added the version I wanted, eg. #v2.0.2
You need to have GOPATH determination. If you don't, create a folder which named as go and it needs to have src,pkg,bin folders.
When you install successfully, you can see bee file in bin folder.
NOTE: You can see go environment with go env command.
The goal is to set up formatting for bash scripts (.sh files). So I'm trying to play around with the .sh formatter. From the project's github quick start section; I have go installed and have pulled in the shfmt module like so: GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt. But on trying to invoke the shfmt command. I'm getting the common command not found error. How do I actually use the shfmt command. My assumption is this is plug and play i.e. I don't need to actually go and fiddle around with PATHs or ENVs.
The command is installed as $HOME/go/bin/shfmt (unless GOBIN is set, then it's $GOBIN/shfmt):
$ go help install
usage: go install [-i] [build flags] [packages]
Install compiles and installs the packages named by the import paths.
Executables are installed in the directory named by the GOBIN environment
variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH
environment variable is not set.
The installation happens with a help of go install command as Peter mentioned. I would like to make a step by step that worked for me on Windows 7 machine, because I bet there are some of you who don't know anything about go language and don't even want to hear about it:
Install go language from golang.org (I used installer for Windows of course)
Download .sh formatter and unzip it somewhere
Navigate to the root directory ..\sh-master with your favourite terminal (I use GitBash or you can use cmd.exe which every Windows has by default)
Run command go install and installation should start
Once installation is done, through terminal (GitBash or cmd) navigate to $HOME/go/bin (on Windows by default it's under C:\Users\your_username\go\bin)
From here you can use the shfmt command like so shfmt -l -w yourBashScript.sh
Voila! now your bash script yourBashScript.sh is modified and formatted)
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.
I'm trying to install React Native on Mac but I'm not able to get past the first step.
npm install -g expo-cli
This seems to work but when I run the next step expo init AwesomeProject I'm getting this error.
-bash: expo: command not found
I also do not have a .npm-global folder. I'm running npm 6.13.4 on Mac OS X 10.15.2.
This might be a local environment issue.
Your computer should know where to look for the commands you're using, it's likely that your mac is not looking for the correct folder.
In order to expo command works, you must have /Users/yourUser/.npm-global/bin in your $PATH commands.
Open your global bash_profile file vim ~/.bash_profile.
add export PATH=$PATH:~/.npm-global/bin.
Save the changes, and right after in your command line:
source ~/.bash_profile
Now you can try the command again!
Important Note: .bash_profile will run only on login shells. For non-login shells, you would need to create or edit .bashrc with this line above.
For example, I'm trying to install pipenv using the following commands:
$ pip3 install --user pipenv
$ cd ~/Documents/myproject
$ pipenv install requests
zsh: command not found: pipenv
It seems that the issue can be resolved if I run sudo ln -s ~/.local/bin/pipenv /usr/bin. Is this a safe thing to do? I've also been having this issue with several other packages, like tensorboard and xflux. Is there something wrong with my system that makes it such that I need to manually create a symlink every time? How can I change things so that packages can install normally without me having to do this every time?
The problem you are having is that the tools you are installing are being installed in non-standard locations and are not being included in your PATH. One way to resolve this would be to include the paths in your PATH environment variable. In order for these programs to be in your path every time you login, do this (assuming you are using zsh as your shell):
1) Open ~/.zshrc using vim or any other editor:
vim ~/.zshrc
2) Append the following to this file:
export PATH=$PATH:/path/to/dir/containing/pipenv
Remember to replace /path/to/dir/containing/pipenv with the appropriate path.
3) Source your ~/.zshrc so that the path is included in your current session:
source ~/.zshrc
4) Now everytime you login, the paths should be available in your environment and you won't need to create symlinks.