Install go (golang) on Raspbian - linux
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.
Related
Cobra init not working,: Command not found
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
Compiling x64Linux2.6gcc file
I am working on a data distribution service protocol using eProsima FastRTPS in Linux (Ubuntu), but I am not able to make it run because FastRTPS has file "makefile_x64Linux2.6gcc" which i need to compile but i dont know the commands to do it . I have tried make option, too, but still having the same problem. Is there any command for compiling .6cc file?
You must compile using cmake as indicated in the README file from eProsima Fast-RTPS github In you case: $ cmake -DTHIRDPARTY=ON .. $ make $ sudo make install You can install in an user's folder setting -DCMAKE_INSTALL_PREFIX=/path on the cmake command. $ cmake -DTHIRDPARTY=ON -DCMAKE_INSTALL_PREFIX=~/path/Fast-RTPS .. $ make $ make install
Actually everything is working fine now. The problem was I was only using make command. If I use make -f command it will make an executable file of it.
OpenShift oc command line with Cygwin
I'm running Cygwin 64bit but can't seem to get OpenShift oc command line to work I downloaded oc.tar.gz ( from here https://mirror.openshift.com/pub/openshift-v3/clients/3.6.173.0.5/linux/oc.tar.gz ), unzipped it and placed it in my path in /usr/bin When I try to run: oc login I get the following. -bash: /usr/bin/oc: cannot execute binary file: Exec format error Do I need to somehow 'install' the executable ? Any help would be much appreciated.
In addition to #Graham Dumpleton's answer: open cygwin and check for directory /usr/local/bin mkdir -p local/bin $ cd /usr/local/bin if it does not exists: $ mkdir -p local/bin finally extract the windows package: $ cp /cygdrive/c/Users/me/Downloads/oc-3.5.5.31.24-windows.zip /usr/local/bin/ unzip oc-3.5.5.31.24-windows.zip $ oc version oc v3.5.5.31.24 kubernetes v1.5.2+43a9be4 features: Basic-Auth
Use the Windows binary from the following page: https://github.com/openshift/origin/releases
From project homepage https://www.cygwin.com/ Cygwin is not: a way to run native Linux apps on Windows. You must rebuild your application from source if you want it to run on Windows. a way to magically make native Windows apps aware of UNIX® functionality like signals, ptys, etc. Again, you need to build your apps from source if you want to take advantage of Cygwin functionality.
Composer & Cygwin
Composer doesn't run correctly in Cygwin if you try to install it "globally". Putting composer.phar into /usr/local/bin/composer, then trying to run it will result in the error: Could not open input file: /usr/local/bin/composer
Just tripped over the same problem and found a solution. Posting it here, just in case I'll ever have to look it up again. Set up a bin directory right under /home/my-username: cd ~ mkdir bin Move the composer.phar (or any other of those nifty new PHP imps that are on the rise) into the ~/bindirectory and make sure to set it's execution bit: # Notice how I got rid of the superfluous `.phar` extension mv /path/to/composer.phar ~/bin/composer chmod +x ~/bin/composer Tell cygwin to include your ~/bin directory in the search path: Open up the file ~/.bash_profile and uncomment the following paragraph ... # Set PATH so it includes user's private bin if it exists if [ -d "${HOME}/bin" ] ; then PATH="${HOME}/bin:${PATH}" fi Now, for the most important part: A wrapper script that helps Win's native PHP resolve Unix style paths (which is causing the problem after all as Windows doesn't know how to handle /cygdrive/... paths). cd ~/bin touch php chmod +x php After editing the wrapper script ~/bin/php should read: #!/bin/bash # e.g. php="/cygdrive/c/Program Files (x86)/php/php.exe" php="/path/to/php.exe" for ((n=1; n <= $#; n++)); do if [ -e "${!n}" ]; then # Converts Unix style paths to Windows equivalents path="$(cygpath --mixed ${!n} | xargs)" case 1 in $(( n == 1 )) ) set -- "$path" "${#:$(($n+1))}";; $(( n < $# )) ) set -- "${#:1:$((n-1))}" "$path" ${#:$((n+1)):$#};; *) set -- "${#:1:$(($#-1))}" "$path";; esac fi done "$php" "$#" Now restart your shell and it should correctly invoke the PHP interpreter whenever it stumbles upon a #!/usr/bin/env php shebang. Simply issue a: composer --help
How about this one? In ~/.bashrc, add: alias composer='php c:\\your\\path\\to\\composer.phar' Restart cygwin or reload the bashrc by running source ~/.bashrc Works for me using both Cygwin's native php.exe and XAMPP's Windows-specific one.
I think what might work is to build a proxy instead: Put composer.phar in /usr/local/bin/composer.phar Create a bash proxy as /usr/local/bin/composer with the following: #!/bin/sh c:/path/to/php c:/path/to/composer.phar $# chmod +x /usr/local/bin/composer
Try this: Install Cygwin PHP and use it to run composer in Cygwin. You can choose one of two ways to work fine with PHP+Composer in Cygwin: Install Cygwin PHP and install composer.phar in Cygwin. Install Windows PHP and install Winodows Composer, then call then from Cygwin. (Windows XAMMP+Composer with alias in cmd) Your problem is caused by that Cygwin Composer is ruining by Windows PHP on Cygwin, so it can not recognize the file path. After install Cygwin PHP, the composer will integrates with Cygwin PHP then fit to Cygwin's filepath. Cygwin PHP extensions for composer usage: php php-json php-mbstring php-phar php-zip php-posix You can install other PHP extension when composer's package is needed such as php-xmlwriter, php-tokenizer, php-ctype. Installation commands guide: If you have already installed apt-cyg, there are installation command above: apt-cyg install php php-json php-mbstring php-phar php-zip php-posix apt-cyg install php-xmlwriter php-tokenizer php-ctype Then install Composer via Cygwin PHP: php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php php -r "unlink('composer-setup.php');" chmod +x ./composer.phar mv ./composer.phar /usr/bin/composer composer -v Conclusion I recommend using Windows PHP + Windows Composer, and call then in Cygwin, it because the Cygwin PHP is not much stable than Windows PHP.
I had the same problem. After reading the final instruction from composer installer, it says that the $PATH variable should be reloaded. I rebooted my computer and then linked the Composer bin to /usr/local/bin. First locate the composer bin : /cygdrive/c/ProgramData/ComposerSetup/bin/composer Then according to Seldaek answer, after trying a non-working symlink, I did : nano /usr/local/bin/composer #!/bin/sh /cygdrive/c/ProgramData/ComposerSetup/bin/composer $# chmod +x /usr/local/bin/composer And it's working.
What I did (very simple): Install Composer normally with the Windows installer Open a Cygwin console an type composer you will see something like Could not open input file: /c/route/to/your/composer/installation/bin Create an alias composer='composer.bat' on your bash profile or bashrc or whatever Done I'm running Windows 8.1
I was having this issue. Most of the responses were over my head but I fixed it with no problems. Step 1) Reinstall Composer globally as per https://getcomposer.org/download/ Step 2) Leave it alone. All the special stuff you want to do, don't do that. Step 3) Download the latest setup-xxx.exe from https://cygwin.com/ Step 4) Click it with your mouse. NOTE: During step 5 you will feel a sudden urge to read instructions, browse the web for info and start checking little boxes on the menu. Don't do that. Step 5) Click 'next' until it stops asking. It will look at your existing settings, fix things up and add any missing dependencies. This worked for me.
Getting composer to work globally inside Cygwin is a pain in the butt... The solutions I have come up with: Don't use it globally. If you are using the PHP CLI from a Windows installation, it won't recognize the Linux paths that Cygwin uses. What I have done is put it in the base directory of all the projects I use composer with, and do ../composer.phar to run it. It works fine this way, and it's almost globally available... Download, and compile your own PHP binaries within Cygwin... Yea, kind of a overkill.
I solved the problem like this in a Cygwin/XAMPP setup: Install composer.phar to XAMPP's php directory Create an executable Bash script named composer in XAMPP's php directory: #!/bin/bash script_dir=$(cygpath -w $(dirname $0)) php "$script_dir/composer.phar" $# It's important to use cygpath -w to convert the path to a path in Windows form. Make sure XAMPP's php directory is accessible in Cygwin's $PATH: $ export PATH=$PATH:/cygdrive/i/dev/server/xampp/php Now it's possible to call composer from anywhere you like without problems: $ composer -V Composer version 264f433ca3f007d39568b3722b4bf418f58ba15b
I fixed it by adding a /usr/local/bin/composer file: nano /usr/local/bin/composer with the following content: #!/bin/bash /cygdrive/c/wamp/bin/php/php5.4.3/php "C:\wamp\bin\php\php5.4.3\composer" Basically, you have to call PHP with a Windows style path, not a cygwin path.
The easiest way is to install composer using the Windows installer from their website and then copy the two files 'composer' and 'composer.phar' from "C:\ProgramData\Composer" into a directory which is in the PATH variable. E.g. you could copy the files into the /bin/ directory of cygwin. Afterwards you can again uninstall the "Windows version" of composer. Update! This is what I did: Install PHP and needed modules from the Cygwin Ports project Download the latest composer snapshot Rename 'composer.phar' to 'composer' and save it to /usr/local/bin Open /bin/dash.exe and run '/usr/bin/rebaseall' Also if 4. gives you an error, composer should run now
I suggest you use babun, it is based cygwin, but you can install package by pact, you can do this: pact install php php-json php-phar php -r "readfile('https://getcomposer.org/installer');" | php then enjoy yourself.
I was having trouble getting Composer to work in Cygwin and none of the solutions above were resolving my problem. Eventually I stumbled across this comment in the Composer github bugs discussion: Yeah TBH using php from cygwin isn't a great idea, cygwin is just too different an environment. Too many hacks that create failures.. In any case closing here as there isn't much we can do I'm afraid :) I don't know precisely where composer/Cygwin/php was tripping up, but, broadly, my problem was that I had two conflicting installations of PHP in environmental variables, one from an installation of WAMP, and another installed with Cygwin. The Cygwin PHP installation seemed to be struggling with some sort of path issue. I removed it, using only the WAMP PHP, and composer ran in Cygwin just fine.
Install OpenCL(AMD SDK kit) on linux without ROOT privilege
I am trying to install OpenCL(AMD) on linux, but I am stuck on the last step(install ICD) It seems like ICD HAS to be installed at /etc/OpenCL/vendor, but I don’t have root access to the computer. Is there any way to make OpenCL work without installing ICD? (or maybe through an environment variable to add search path for ICD files?) It just seems really inconvenient for people like us when ICD file path is hardcoded.
Put the ICD-files in /some/path/icd and then export the path like so: export OPENCL_VENDOR_PATH=/some/path/icd It used to work in previous versions at least. I would be surprised if they changed it.
Here is a sketch of how to do a "user" or "local" install of the AMD OpenCL SDK without administrator privileges. Step 9 also provides a method to use the AMD OpenCL platform along with selected platforms installed system-wide. The installation directory /local/install/path and current SDK version just need to be modified to suit. Download the AMD OpenCL SDK 64 bit. $ tar -xvzf AMD-APP-SDK-v2.8-RC-lnx64.tgz $ tar -xvzf icd-registration.tgz $ cd AMD-APP-SDK-v2.8-RC-lnx64 $ mkdir /local/install/path $ cp -r lib /local/install/path $ cp -r include /local/install/path $ cp -r ../etc /local/install/path Optional: make symbolic links for desired system installed platforms: $ ln -s /etc/OpenCL/vendors/nvidia.icd /local/install/path/etc/vendors/nvidia.icd $ export OPENCL_VENDOR_PATH=/local/install/path/etc/vendors $ export LD_LIBRARY_PATH=/local/install/path/lib/x86_64:$LD_LIBRARY_PATH $ cc -I/local/install/path/include -L/local/install/path/lib/x86_64 -lOpenCL demo.c $ ./a.out
Just an update on this as I suddenly found myself having the same issue (again). I had to disable the buggy Mesa icd which apparently is crashing under non-root runs. Frustrating as it's more a problem with the API handling errors while listing each platform more than an error with permissions or clinfo. Make sure to disable each platform icd to isolate which one is having issues. Hope this helps someone later.