Aerosol Posted December 30, 2014 Report Posted December 30, 2014 Some time ago, when i just started to use golang, golang project's structure organizing, this magic $GOPATH and other things was strange for me. No, it wasn't bad, just nothing like i have used before. It's simple to understand with erlang, at least for the start, you must just install erlang, to create project, to add rebar with deps and that's all. Something like this with nodejs project bootstraping. There are clear and intuitive package managers which downloads project's dependencies and puts it to the project dir. Another case with Golang && go get. They are very cool, but not for the first look. You read it's documentation, execute all instructions and than get something like go can't find `projectname` in $GOPATH and $GOROOT. So i created simple bash script which will help you to set up golang environment from the scratch. It makes 3 simple things:Creates directories for Golang compiler and your future projectsDownloads golang compiler and builds itPuts golang/bin/ and directory with your projects to $GOPATHThat's all. Very simple. Of course this script is not for a professional golang developers. It's primarily for two points:For newbie gophersFor fast setting up golang environmentHere is the script: #!/bin/bash## Bash script for fast setting up Golang environment## Usage:## sudo chmod +x gostartup && ./gostartup#red="\e[31m"green="\e[32m"nocolor="\e[0m"bashrc="/home/"$USER"/.bashrc"echo -e "Where do you want to store golang projects [default: /home/$USER/go] \c:"read gopathif [[ $gopath == "" ]]then gopath="/home/$USER/go/"fiif [[ "${gopath: -1}" != '/' ]];then gopath=$gopath"/"figobin=$gopath"go"projects=$gopath"go-projects"struct=$gopath"go-projects/src/github.com"$github_userecho -e "What's you Github username: \c'"read github_userif [[ $github_user == "" ]]then echo -e $red"[Error]: Github username can't be empty"$nocolor exit 0fiecho -e "Do you want to get last golang compiler [y/n]: \c"read getgoif [ ! -d "$gopath" ]; then mkdir $gopathfiif [ ! -d "$gobin" ]; then mkdir $gopath"go"fiif [ ! -d "$projects" ]; then mkdir $gopath"go-projects"fiif [ ! -d "$struct" ]; then mkdir -p $gopath"go-projects/src/github.com/"$github_userfiif [[ "$getgo" == "y" ]];then hg clone -u release "https://code.google.com/p/go" $gopath"go" exec $gopath"go/src/all.bash"fiecho "export GOPATH="$gopath"go-projects" >> $bashrcecho "export PATH=$PATH:$GOPATH/"$gopath"go/bin" >> $bashrcecho -e $green"done" $nocolorexit 0Source Quote