Need help on setting up Beego and Bee dev tool - go

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.

Related

I get "laravel: command not found" on Ubuntu 20.04

I did a fresh install of Ubuntu 20.04 LTS (Focal Fossa), installed Apache, PHP, MySQL and PHP Composer seemingly without issue. However, I still cannot get laravel -V to give me a version number.
I have looked at a multitude of YouTube videos and tried my interpretation of the recommendations found here on Stack Overflow. How can I fix it?
Here's the output on my shell $PATH.
You must add PHP Composer binaries folder to your $PATH if you'd like to call the binaries globally.
A) Make sure you have the latest Laravel installer:
composer global require laravel/installer
B) Add composer bin folder to your $PATH:
Edit your .bashrc file: gedit $HOME/.bashrc
Add the following line: export PATH="$PATH:$HOME/.config/composer/vendor/bin"
C) Use the source command to force Ubuntu to reload your .bashrc file:
source $HOME/.bashrc
D) Try to output Laravel installer's version:
laravel -V
Additional explanations as requested:
To execute a command from the Linux terminal, you need to tell Linux where the program is located.
For example, you could have launched Laravel installer using the full path: $HOME/.config/composer/vendor/bin/laravel -V
But instead, you wanted to be able to call the laravel -V command directly because you don't want to type the full path every time.
Since you are on Ubuntu, the default shell program is Bash. You need to tell Bash where to look when you type a command. In this case, you want Bash to look in the $HOME/.config/composer/vendor/bin/ folder.
The configuration file for Bash is a hidden file called .bashrc located in the user home folder. Bash stores the list of special folders in a variable called $PATH. To add a new folder, we simply added it to the $PATH variable.
If you type echo $PATH in your terminal, Bash will output the content of the $PATH variable and you will see a list of folders.
Now you may ask: "Why did I have to do this? I usually don't have to mess with my Bash configuration". Yes, this is because you usually install Ubuntu packages and they are configured to work out of the box. In this case, you installed a composer package in your home directory and it's therefore up to you to configure it the way you want.
You may need to do source $HOME/.bashrc every time you open u a new terminal windows and then do laravel -v

How to get the sh formatter up and running?

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)

Cannot Install Delve Go Debugger on Mac

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.

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)

After install a golang package, it doesn't work

I'm new on golang. According this instructions, to install go-bindata, I should use this command:
$ go get -u github.com/jteeuwen/go-bindata/...
I did it. After that, I checked on $GOPATH/src/jteeuwen/go-bindata/ and there's a file go-bindata.a. It seems like it was installed, but it doesn't work:
$ go-bindata
-bash: go-bindata: command not found
Please, what am I doing wrong?
EDIT: I'm using OS X
You'll need to add $GOPATH/bin to your $PATH.

Resources