Problem with installing Go on Ubuntu 20.04 server - go

I am new to Ubuntu and am trying to install Go onto my server, however I get an error when trying to use Go.
Command 'go' not found, but can be installed with:
sudo apt install golang-go # version 2:1.13~1ubuntu2, or
sudo apt install gccgo-go # version 2:1.13~1ubuntu2
The commands I used to install Go are below.
$ wget https://dl.google.com/go/go1.15.10.linux-amd64.tar.gz
$ sudo tar -xvf go1.15.10.linux-amd64.tar.gz
$ sudo mv go /usr/local
Then I appended the following to the bash_aliases file.
$ vi ~/.bash_aliases
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
What am I doing wrong here?

I will give you some suggest.
check your path var
echo $PATH
Since you edit ~/.bash_aliases, I think you maybe not source this file.
please try source ~/.bash_aliases.
or try
export $PATH=$PATH:/usr/local/go/bin
beside ~/.bash_aliases may not be load by default. see if . ~/.bash_aliases is in your ~/.bashrc file.
Check if bin can run
/usr/local/go/bin/go version
if have error, maybe is the package you download is wrong. checksum the tar package(for example: md5sum xxxx.tar.gz).
check the default path of go
which go
if go bin not in /usr/local/go/bin/go, you should delete the go bin that shown by which go

Using APT, there is an official package you can install using Ubuntu
Open a terminal and run:
sudo apt update
sudo apt install golang-go
Depending on your version of Ubuntu, you may have to run:
sudo apt install golang
Hope this helps! Its my first answer!

Related

Go Command Not Found” Error When Using Sudo

sudo go install github.com/KathanP19/Gxss#latest
sudo: go: command not found
I try to install tool with sudo command but it shows sudo: go: command not found....any solutions?
but i installed go
─(spark㉿usr)-[~]
└─$ go version 1 ⨯
go version go1.18.1 linux/amd64
echo $PATH
/home/spark/.cargo/bin:/home/spark/.local/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin
sudo has its own $PATH which is defined by the secure_path setting in your sudo config.
To fix it:
Open your sudo config sudo visudo
Locate the line staring with Defaults secure_path =
Add :/usr/local/go/bin to the end of the line
After saving the config, you should be able to use go with sudo

How to update golang on codeanywhere.com with Ubuntu

How to update golang on codeanywhere.com with Ubuntu 14.04?
The default container uses the version from Ubuntu repos, instead of golang PPA.
As of writing it's 1.6 and the newest version is 1.9.
(can't comment yet) Just an additional information, the steps in Paweł Prażak's answer work when you run on a Blank Container. If you run them on a Go predefined stack it won't update.
I also recommend to change the GOPATH value to your workspace, running
export GOPATH=$HOME/go
Then run go env to check if the values are correctly updated.
Thanks for the answer by the way, Paweł!
You can easily install the latest golang release in the container by using this script:
git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh
Full details: https://github.com/udhos/update-golang
Create and new Blank Container with Ubuntu:
Connect to the container with SSH.
Follow the instructions on the official wiki.
First install the add-apt-repository support:
sudo apt-get update
sudo apt-get install -y software-properties-common
Now install the recent version of golang (refer to the wiki for up to date instructions):
sudo add-apt-repository ppa:gophers/archive
sudo apt-get update
sudo apt-get install golang-1.9-go
Make sure to put the binary on PATH, e.g.:
sudo ln -s /usr/lib/go-1.9/bin/go /usr/local/bin/go
Now the newer version should be available:
$ go version
go version go1.9.2 linux/amd64
Add $GOPATH pointing to the workspace and add $GOPATH/bin to $PATH in ~/.profile:
cat << EOF >> ~/.profile
export GOPATH="\$HOME/workspace"
export PATH="\$GOPATH/bin:\$PATH"
EOF
Apply the new ~/.profile:
. ~/.profile
Also make is missing, if you need it:
sudo apt-get install build-essential

zsh command cannot found pip

How can I use pip in oh-my-zsh? I was trying to install nltk through pip, but it told me zsh: command not found: pip. When I check plugins under .oh-my-zsh/custom/plugins, there is a folder named pip. I don't know what the problem is.
Edit:
$ echo $PATH
/home/xxx/bin:/usr/local/bin:/home/xxx/bin:/home/xxx/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ type pip
pip is an alias for noglob pip
Maybe you have installed both python2 and python3. python3 may have been installed later.
You may try to use pip3 instead of pip.
First, input the command:
pip3 -V
If you see the version, the pip3 can be used.
Then you can input command line to install nltk:
pip3 install nltk
I got a way to help you use pip in zsh. We can use nano to edit files. In nano, ctrl+X to save and exit
In the ~ directory, input the command:
nano .bash_profile
You may see some codes like:
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
Copy them and paste them to the end of .zshrc file by using command:
nano .zshrc
Then input the command:
pip -V
If you see the version, pip can be used.
In case you do
which pip
and it doesn't show the path, just do
which pip3
This will print the path which is /usr/local/bin/pip3
Then do open ~/.zshrc or nano ~/.bash_profile.
Make alias for pip like:
alias pip=/usr/local/bin/pip3
N.B: You copy that line above and paste in your .zshrc file.
After do source ~/.zshrc and close .zshrc
For me it's working to do
python -m pip install [package_name]
instead of
pip install [package_name]
If you installed python3.x, you should run with pip3(not pip)
So you are using oh-my-zsh framework for zsh or Z shell.
First, try the command:
pip3 -V
If you get something like this below, that means you have the pip3 package already and must be having python3 as well.
pip 22.0.4 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)
Then edit your .zprofile instead of .bashprofile as you are using zsh. This is the command.
nano ~/.zprofile
Then it should have the two alias like this.
# Setting PATH for Python 3.10
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
export PATH
alias python=python3
alias pip=pip3
Make sure you save it. Exit and Re-open you terminal. Type the command:
pip -V
It should have the same result as the pip3 -V like this:
❯ pip -V
pip 22.0.4 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)
Then you can use pip or pip3 interchangeably for installing your nltk package like this.
pip install nltk
I'm on MacOS and use ZSH. It seems pip 2.7 can't be found, although it is installed. I believe my paths to "pip" are linked wrong (I also have python3 and pip3 installed via brew).
To get around the issue I created an alias. If you don't have an .aliases file, create one in your homedir. Then open the file:
nano ~/.aliases
and add:
## PIP for python2.7 ##
alias pip="python -m pip "
You need to tell ZSH to pick up the alias file (assuming you don't have this setup already). Open your .zshrc:
nano ~/.zshrc
The add the following near the bottom of the file:
[ -f "$HOME/.aliases" ] && source "$HOME/.aliases"
From the terminal, run:
source ~/.zshrc
Or quit your terminal and reopen it.
Now you can run:
pip install <command>
Edit your rc file:
vim ~/.zshrc
Find the config plugins and delete the pip entry.
In a new terminal:
which pip
This will show you the real path of pip
If you're running into this issue, it probably is due to versioning complications. Python 2 versus Python 3 on your OS may be resolving unexpectedly. Below is a quick workaround to get you to functioning behavior.
Try using the below for Python 2:
python -m pip install <command>
Try using the below for Python 3:
pip3 install <command>
In my case my OS was Ubuntu 20.04 and the pip doesn't come with python.
So, i've installed pip through the command
sudo apt install python3-pip
and I'm done.
To ensure run pip -V or pip3 -V
My pip script is missing for some reason, so I have to install it.
$ python -m ensurepip --upgrade
More methods can be found here:pip installation
You should consider upgrading.
Enter this in your terminal
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 -m pip install --upgrade pip
and then...
Type: pip -V

Homebrew installs nvm but nvm can't be found afterwards?

I'm using homebrew and oh-my-zsh on a fresh OSX 10.10.1 install. I got nvm via homebrew and then attempted to run it but says - zsh: command not found: nvm
Any idea what the problem is? I was able to install and use git just fine...
UPDATED 9/20/2019
As stated by more recent answers from DarkPurple141 and Elise van Looij. nvm doesn't appear to be compatible with homebrew. This is also stated in the official nvm-sh repo located here.
Homebrew installation is not supported. If you have issues with
homebrew-installed nvm, please brew uninstall it, and install it using
the instructions below, before filing an issue.
Note: If you're using zsh you can easily install nvm as a zsh plugin.
Install zsh-nvm and run nvm upgrade to upgrade.
The following steps should help:
$ brew uninstall nvm
$ brew cleanup (just for good measure)
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
Check that nvm was installed correctly by running $ command -v nvm.
4.a If the response is anything other than $ nvm, add the following two lines to the ~/.bash-profile file:
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
4.b Restart your computer (you can try closing Terminal and restarting it first)
4.c $ command -v nvm should now return nvm`
Now update Node.js with $ nvm install --lts
Update npm: $ nvm install-latest-npm
$ npm install --global mocha. Finally, success! Well, for me and I hope for you too.
Did you follow the instructions listed in the caveats?
[~] brew info nvm
nvm: stable 0.20.0, HEAD
https://github.com/creationix/nvm
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/nvm.rb
==> Caveats
Add the following to $HOME/.bashrc, $HOME/.zshrc, or your shell's
equivalent configuration file:
source $(brew --prefix nvm)/nvm.sh
Node installs will be lost upon upgrading nvm. Add the following above
the source line to move install location and prevent this:
export NVM_DIR=~/.nvm
Without the extra config it doesn't look like it will find NVM by default..
There are TWO things you need to do. Follow the caveats shown after installing nvm via brew, and THEN you need to activate/reload the .bash_profile changes.
Run brew install nvm
Follow caveats shown in console, mine were as follows, yours MAY be different!:
Add the following to ~/.bash_profile or your desired shell
configuration file:
export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"
Run . ~/.bash_profile to apply the changes you made to your .bash_profile file
I've spent a couple of hours going round and round on this issue, but I've come to the conclusion that DarkPurple141 is right: nvm just isn't compatible with Homebrew, as they state on their Github nvm-sh/nvm Node Version Manager. Homebrew will install nvm and everything looks fine, until one tries to get npm to install a module, Mocha in my case. That threw me right back to the dreaded error:
ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
NOTE: On step 3, make sure to replace version with correct release.
The solution, on MacOS 10.14 Mojave, was:
$ brew uninstall nvm
$ brew cleanup (just for good measure)
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
Check that nvm was installed correctly by running $ command -v nvm.
4.a If the response is anything other than $ nvm, add the following two lines to the ~/.bash-profile file:
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
4.b Restart your computer (you can try closing Terminal and restarting it first)
4.c $ command -v nvm should now returnnvm`
Now update Node.js with $ nvm install --lts
Update npm: $ nvm install-latest-npm
$ npm install --global mocha. Finally, success! Well, for me and I hope for you too.
While the accepted answer does technically work, it's worth noting that Homebrew installation is not officially supported by the nvm package. The recommended way to avoid issues like those raised above is to apply either of the below methods of installation.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
# or wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
source: https://github.com/creationix/nvm
To install nvm, brew install nvm
To run nvm after installation or just once, $(brew --prefix nvm)/nvm.sh
To run nvm everytime zsh opens
nano ~/.zshrc
Add this line source $(brew --prefix nvm)/nvm.sh
The reason you would need to reload your bash profiles or any other bash files might be because the command nvm may not be a program but a function that is defined and can only be used if the corresponding bash file is sourced.
On a system that I checked
which nvm
does not work but
nvm list
does. This means that you can use the word "nvm" to invoke something. That something isn't a program. In the current case, it is a function which can be verified by
typeset -F | grep -P ' nvm$'
which outputs
declare -F nvm
which means nvm is a function, whose body can be inspected by doing
type -F nvm
One possibility if brew was used is that the nvm may be unlinked, especially if it was installed by another MAC OS user.
In this case, execute:
brew link nvm
I'd like to add that nvm's location on github changed and the version bumped.
The curl command now should be:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
if you happen to be using fish shell, consider https://github.com/jorgebucaran/nvm.fish
Instructions from
lukechilds/zsh-nvm#as-an-oh-my-zsh-custom-plugin
If you are using mac os + zsh + oh-my-zsh:
Clone zsh-nvm into your custom plugins repo
git clone https://github.com/lukechilds/zsh-nvm ~/.oh-my-zsh/custom/plugins/zsh-nvm
Then load nvm as a plugin in your .zshrc file
plugins+=(zsh-nvm)
Keep in mind that plugins need to be added before oh-my-zsh.sh is sourced.
f.e.
$ nano ~/.zshrc
// edit .zshrc contents
...
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
# docs: f.e. https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/kubectl
plugins=(zsh-nvm)
source $ZSH/oh-my-zsh.sh
...
Finally reload the configuration $ source ~/.zshrc

Installing osm2pgsql from source not actually installing?

I'm trying to install osm2pgsql from source on a Mac using Terminal.
I ran these commands:
git clone git://github.com/openstreetmap/osm2pgsql.git
cd osm2pgsql
./autogen.sh && ./configure && make
And it runs, but then if I try to run an osm2pgsql command, it says:
-bash: osm2pgsql: command not found
There are no further instructions online about how to install from source, so I'm not sure what I'm missing here.
Anyone help me?
Thanks
You might need to install the build-essential and automake packages.
Type the following in the terminal (before trying to install osm2pgsql):
sudo apt-get install build-essential
sudo apt-get install automake
sudo apt-get install checkinstall
You need to add it to your path! To "install" something is really just to let the OS know where it is, because it's too dumb to figure that out on its own, even if you're in the same directory with it. In Unix, every command is a program; when you enter a command, the OS checks the "path" which is just a list of directories where that command might live.
First of all, to test that it's compiled and working properly in its own directory:
./osm2pgsql
If that works, add the current directory to the path variable:
export PATH=$PATH:`pwd`
Now you can execute the command from anywhere.

Resources