Cobra init not working,: Command not found - linux

I am following this guide.
***#pop-os:~/go/src/foo$ cobra init --pkg-name foo
Command 'cobra' not found, but can be installed with:
sudo apt install cobra
My setup:
I have go 1.16 installed
$ go version
go version go1.16.3 linux/amd64
my $GOPATH is set to ~/go
$ go env
...
GOPATH="/home/***/go"
What I have done:
I used the command
$ go get -u github.com/spf13/cobra/cobra
In my bin's dir I now find cobra
***#pop-os:~/go/bin$ ls
cobra
...
What am I doing wrong?

Use
go mod init <MODNAME>
~/go/bin/cobra-cli init
or keep reading to learn how to to make the cobra-cli command available on the command line.
This seems to be an issue of $PATH configuration. Because the cobra-cli command is not found, the path ~/go/bin is not part of the $PATH variable. One can add the path like this:
export PATH="~/go/bin:$PATH"
and then use the cobra-cli command on the command-line. One can add that export ... command to ~/.bashrc or a similar file to have the PATH configured properly on startup.

The cobra command is now become cobra-cli.
see https://github.com/spf13/cobra#usage

Related

Atom Script can't find the path for Python 3 on Mac

When using the script addon for Atom it brings up:
Unable to run
/usr/bin/python3
Did you start Atom from the command line?
atom .
Is it in your PATH?
PATH: /usr/bin/python3:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/bin/python3:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands:~/.dotnet/tools
How do I get Atom to recognize Python 3?
I tried installing Python using Homebrew and it is installed to /usr/local/bin/python3 as well as using the Terminal to add all of the suggested path locations to /etc/paths.
You need to properly configure the script package to use a profile that points to the correct python3.
Open a Terminal and navigate to the directory containing your scripts.
$ pwd
/Users/cerberus/Scripts
Get the path to python3
If you installed it via Homebrew, then it should be at:
$ python3 -V
Python 3.7.3
$ which python3
/usr/local/bin/python3
You can also check that Homebrew already updated PATH to add /usr/local/bin, but unless you did something wrong with the Python installation, this part is unnecessary.
$ echo $PATH
.../usr/local/bin/:/...
Now, start Atom from the command line as explained in the package docs
Make sure to launch Atom from the console/terminal. This gives atom
all your useful environment variables. Additionally, make sure to run
it with the project path you need.
$ cd /path/to/scripts
$ atom .
OR
$ atom /path/to/scripts
Go to Packages > Command Palette > Toggle (or use CMD+SHIFT+P)
Select Script: Run Options
Input the path to your scripts and the path to the python3 command
NOTE: On my machine, just setting python3 also works. But if you are having problems with your python path, you can try to specify the full path (/usr/local/bin/python3) as shown.
Save the profile (ex. as "Python3")
Now, when you want to run your Python scripts, use the Script: Run with Profile command and then select the profile you just created.
That should work now.

dotnet-install.sh not adding dotnet command on Ubuntu

I am not a Linux user so this might be a easy fix but I have tried the following:
first I install it using the command curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin for which I get the following result:
dotnet-install: .NET Core SDK version 2.1.403 is already installed.
dotnet-install: Adding to current process PATH:
/home/<!username!>/.dotnet. Note: This change will be visible only when sourcing script.
dotnet-install: Installation finished successfully.
I do . ~/.profile to reload the profile,
but even after this when I run dotnet I get the following error:
Command 'dotnet' not found, but can be installed with:
sudo snap install dotnet-sdk`
I was expecting the script to do everything and make dotnet available.
TLDR: curl | bash can not modify PATH so it will not add dotnet to your PATH. You need to add dotnet to your path manually. Add export PATH="$PATH:/home/<!username!>/.dotnet" to your ~/.profile (or ~/.bashrc or equivalent) and log out and log back in.
Long version:
When you run a command in the shell (for example, bash), the shell tries to find an executible with the name in the all the paths listed in the environment variable PATH. PATH is generally set to something like /bin:/usr/bin. So when you type a command like curl, your shell looks in both /bin and /usr/bin for an executible file named curl.
You can see what your PATH is by doing env | grep PATH or echo $PATH.
The other important piece of information is how environment variables propagate. It's quite simple, actually:
A program (or process) can only modify its own set of environment variables.
Any child processes that a process creates inherit its environment variables.
What this means is that a program that you execute can not modify the environment variables of another random program. The shell actually provides a special command, export to set its own environment variables (and any child processes it later creates will inherit those).
Note the output at the end of step 1.
Note: This change will be visible only when sourcing script.
If you run curl | bash, it runs bash as a child process. That child process can not modify the environment variables of the program that started it (the shell that invoked curl | bash). So it can not modify PATH to add the location of dotnet to it. It even (helpfully) tells you that it can't.
In step 2, you are reloading ~/.profile. But does it contain any commands to add dotnet to PATH? I dont think so. I know the dotnet-install.sh script has not historically added it. You need to add a line like
export PATH="$PATH:/home/<!username!>/.dotnet"
To your ~/.profile (or ~/.bashrc, or equivalent) manually.
Actually, I would write it as follows to make the change more portable to other users:
export PATH="$PATH:$HOME/.dotnet"
Try running this again:
sudo add-apt-repository universe
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-2.2

Install go (golang) on Raspbian

I checked diverse forums but I still did not make it working.
I like to install go (golang) on my Raspberry PI - Raspbian:
With
sudo apt-get install golang
I installed go and with
export GOPATH=$home/pi/gocode
i set the GOPATH so i tryed to install from a homepage a new program with (sudo go get -u github.com/....) but, I only get "cannot download, $GOPATH not set. For more details see: go help gopath".
I really get crazy for my studip simple mistake that i do not see.
I would be pleased if i get a very detailed "how to do" discription since I am new to Linux and Raspbian, so everything which is made for real dummys should be good enough for me.
Thank you for your help.
This are detailed instructions about how to install Go on Raspbian Stretch from the repositories.
As of today, 2018-01-30, this will install Go 1.7. The most actual version for manual installation from the downloads is Go 1.9.3.
I. Login to your user on the Raspberry Pi (I'm using the default user pi).
II. Install Go (golang)
pi#pi3-2:~ $ sudo apt update
pi#pi3-2:~ $ sudo apt install golang
III. Create a working directory for all your go projects in your $HOME directory. It's best to name it go, as this defaults to the GOPATH in future Go versions (starting with Go 1.8).
pi#pi3-2:~ $ mkdir go
IV. Append the $GOPATH environment variable and modified PATH settings to your .profile
pi#pi3-2:~ $ echo 'export GOPATH=$HOME/go' >> ~/.profile
pi#pi3-2:~ $ echo 'PATH="$HOME/go/bin:$PATH"' >> ~/.profile
V. Logout and Relog with the new settings then check your settings
pi#pi3-2:~ $ go env
GOARCH="arm"
GOBIN=""
GOEXE=""
GOHOSTARCH="arm"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/pi/go"
GORACE=""
GOROOT="/usr/lib/go-1.7"
GOTOOLDIR="/usr/lib/go-1.7/pkg/tool/linux_arm"
CC="gcc"
GOGCCFLAGS="-fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build187598155=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
Especially make sure GOPATH points to your previously created Go working directory. Don't care about setting GOBIN as mentioned in some documentation. It's usually not necessary and Go will automatically use $GOPATH/bin/ for your Go installs.
However, you might also want to check the path settings (/home/pi/go/bin should be included) to make sure you can run the code you installed with go install.
pi#pi3-2:~ $ echo $PATH
/home/pi/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
VI. A few words about the Go working directory structure
Over time, the Go working directory will contain three sub-directories: bin, src and pkg. Except src they will be automatically created, when needed the first time. The structure for user pi will look like this:
/home
/pi
/go
/src
/pkg
/bin
bin will contain all Go executable's you have installed using go install command.
pkg will contain all compiled packages that can be imported into your projects.
src will contain all your source files, either your own or sources downloaded from external repositories.
For eksample the command go get github.com/petergloor/hello-go will automatically fetch and place the source files from the corresponding external Github repository into the local directory $HOME/go/src/github.com/petergloor/hello-go.
As it's rather common to fetch external repositories either for reference or contribution it becomes important to keep your directory structure always well organized and clean.
Apart from that you are free to organize your projects as long they are hierarchically structured below the $HOME/go/src/ directory and follow the rules mentioned in the documentation.
However, to clearly organize my projects I personally always place my projects into $HOME/go/src/github.com/my-github-account even if I don't have an external repository for it.
If you don't have a github account you can likewise use any other external repository account.
As I mentioned, even it's not needed at all I prefere to use my Github account to clearly identify my projects. And even it's not needed I will use the username pi to distinct the user from other project maintainers in the following example.
VII. So let's add a "hello world" project to test our installation.
a) First let's create the project folder and cd into its directory.
pi#pi3-2:~ $ mkdir -p $HOME/go/src/pi/helloworld
pi#pi3-2:~ $ cd $HOME/go/src/pi/helloworld
pi#pi3-2:~/go/src/pi/helloworld $
b) With an editor of your choice create a file main.go with the following content
// helloworld project main.go.
package main
import ("fmt")
// main is the entrypoint of the application.
func main() {
fmt.Println("Hello world! Greetings from Raspberry Pi")
}
Spacing doesn't matter at this point. Go provides a nice tool to do this for you.
c) Now try to run the program.
pi#pi3-2:~/go/src/pi/helloworld $ go run main.go
Hello world! Greetings from Raspberry Pi
pi#pi3-2:~/go/src/pi/helloworld $
In case you get an error, fix it! Carefully, check the spelling and cases (Go is case-sensitive).
d) Next lets format the code:
pi#pi3-2:~/go/src/pi/helloworld $ go fmt
Without a file name this will properly (re-)format all source files within this directory and below.
e) Next let's build helloworld as an executable procram, within this directory.
pi#pi3-2:~/go/src/pi/helloworld $ go build
pi#pi3-2:~/go/src/pi/helloworld $ ls
helloworld main.go
pi#pi3-2:~/go/src/pi/helloworld $
f) Now you can run it.
pi#pi3-2:~/go/src/pi/helloworld $ ./helloworld
Hello world! Greetings from Raspberry Pi
pi#pi3-2:~/go/src/pi/helloworld $
g) Finally let's install the program into the $HOME/go/bin/ directory.
pi#pi3-2:~/go/src/pi/helloworld $ go install
pi#pi3-2:~/go/src/pi/helloworld $ ls $HOME/go/bin
hello-go helloworld
pi#pi3-2:~/go/src/pi/helloworld $
h) If everything is done right it can be run by our pi user from anywhere by just entering the name of the command.
pi#pi3-2:~/go/src/pi/helloworld $ helloworld
Hello world! Greetings from Raspberry Pi
pi#pi3-2:~/go/src/pi/helloworld $ cd ~
pi#pi3-2:~ $ helloworld
Hello world! Greetings from Raspberry Pi
pi#pi3-2:~ $
Congratulations!
as of Nov 2019. (Please note if you need version 1.13+ please wget go1.13.3.linux-amd64.tar.gz manually)
OR sudo apt-get install golang-go - source
You just have to type following commands on your RPi
sudo apt-get update
sudo apt-get install golang --fix-missing
and when you type now go version following should be your output
pi#rpi1:~ $ go version
go version go1.11.6 linux/arm
Additionally, I also had the following installed before running everything
sudo apt-get install make gcc g++
How to install golang:
Download the latest tarball, go1.9.linux-armv6l.tar.gz, to a directory such as /home/pi/downloads.
Then use:
sudo tar -C /home/pi -xzf go1.9.linux-armv6l.tar.gz
to extract the go installation to the directory
/home/pi
creating /home/pi/go
to check use
go version
Which will give you the actual version of go.
It should be go1.9 linux/arm.
Please check with:
go env
or
go env GOPATH
the GOPATH direction
with
ls -a # (used in /home/pi/ )
give you a list of all files and also shows you ~/.profile
with
sudo nano ~/.profile
you can open that file an add the reccommended code for the go directory
export GOROOT=/home/pi/go
export GOPATH=/home/pi/go/bin
close with STRG + O and ENTER and STRG + X
check with
go env GOPATH
then use
source ~/.profile
then you can check again with
go env
Now go should be running on the latest version and should have the correct GOPATH directory
For me helpful was this link: https://tecadmin.net/install-go-on-debian/#
I really hope some others also give detailed descriptions of how to install a program in a brief and detailed way. Instead of 3 lines of single code.

'express' command not found on mac

Definitely a noob question so please don't judge but this has been bothering me for a while.
No more how many times I run $ sudo npm install -g express-generator or $ npm install express -g, everything seems to install but the command $ express still doesn't exist.
I'm running fish shell. Also, I'm assuming this is an issue coming from my PATH file, but I'm lost on if that's .bash_profile or .bashrc.
My .bash_profile has the three lines in it:
export PATH=/usr/local/bin:$PATH
export PATH=/Users/username/.node/lib/node_modules/express-generator/bin/express:$PATH
export PATH=/Users/username/.node/bin/express:$PATH
and my .bashrc file has nothing regarding node in it.
When express installs, it returns:
/Users/username/.node/bin/express -> /Users/username/.node/lib/node_modules/express-generator/bin/express
/Users/username/.node/lib
but when I command which node it returns
/usr/local/bin/
When I try to run $ls -l /usr/local/bin/express it returns:
ls: /usr/local/bin/express: No such file or directory
Cannot find the diagnosis of why the express command won't work after installation.
If you are running fish, your .bash_profile is ignored, of course!
The preferred way to add /Users/username/.node/bin/ to your $PATH in fish is like so:
set -U fish_user_paths $fish_user_paths /Users/username/.node/bin/
that's just something you run once, at the command line - not something you put in a startup file.
If you prefer to use startup files, you can instead modify your ~/.config/fish/config.fish like so:
set PATH $PATH /Users/username/.node/bin/
From the symlink after the install, the express binary should be available in the /Users/username/.node/bin directory. The reason you can't use the binary is because the /Users/username/.node/bin directory is not in your $PATH. Whats in the $PATH is the binary itself.
When you add a directory to your $PATH, you can execute binaries from within the directory. Currently, your $PATH points to the /Users/username/.node/bin/express which does not have any binaries within it. You should correct it to:
export PATH=/Users/username/.node/bin:$PATH

cordova ./create function not found Ubuntu 12.04

I'm digging around in PhoneGap to build a quick prototype we need.
When I navigate to the
~/cordova-2.1.0/bin$
and run
./create ~/jdphonegap com.jdphonegap.app JDPhoneGap
I get the following error
unexpected operator
./create: 48: ./create: function: not found
I'm not the only one:
https://groups.google.com/forum/?fromgroups=#!topic/phonegap/uI_rmd-Gto0
A little help?
Change the first line in create script from
#! /bin/sh
to
#!/bin/bash
Download commons-codec-1.6 from main server:
http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.6-bin.tar.gz
Extract the commons-codec-1.6.jar and place it to the cordova-android/framework/libs/ (need to create libs)
Alternatively change the URL of this package in create script at line 96
Install ant if you don't have it: http://archive.apache.org/dist/ant/ant-current-bin.zip, extract and add the ant bin folder in your PATH
Example for ant installed in /usr/local:
export PATH=/usr/local/ant/bin:$PATH
Then you can run the create script as documented.
see this line of create script:
ANDROID_BIN=$( which android )
if the environment variable "android" is not set it does not work.
In my case, I ran the following command:
export PATH= android-sdk-linux/tools/:$PATH
and with this it worked.

Resources