Sunday, June 2, 2013

Installing Go, Gocode, GDB and LiteIDE

I removed the sections about gocode and GDB. These are not necessary any longer. I also added links for more editors.

Windows
This is a great post by Wade Wegner for installing Go on your Windows Machine:
http://www.wadewegner.com/2014/12/easy-go-programming-setup-for-windows/

Mac OS X
The following instructions will guide you through installing Go on your Mac.


Step 1: Download Go

Open your favorite browser and go to the following website:
http://golang.org/dl/


This will show you all the latest builds for the different operating systems. Darwin is the name for the Mac OS. Download the installer package for your OS version and architecture.

Once downloaded go to your Downloads folder in Finder and double click on the pkg file to start the installation. The installation will put Go in /usr/local/go. Once the installation is complete you will want to check the installation.

Note: Moving forward we will be using both Terminal and Finder. It helps to be able to see all the files in Finder.  Finder by default will not show you everything that is on your hard drive.

To show all files in Finder:

Open a Terminal session. If you don't know where the Terminal program is go to your Applications folder in Finder and then Utilities. Click on Terminal and a bash shell command window will open.

Execute the following commands in Terminal.

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

The killall Finder will reload the Finder program and now you can see all the files.


Step 2:  Check Installation

Open a Terminal session and type the following command

go version

You should see the following if everything installed correctly

go version go1.5 darwin/amd64

Now type the which command to verify the installation is in /usr/local/go

which go

You should see that Go can be found in /usr/local/go/bin

/usr/local/go/bin/go


Step 3:  Set Your GOPATH

You need a single place to store and work on your Go projects. Create a folder called projects from inside your home folder:

cd $HOME

mkdir projects
cd projects
mkdir src
mkdir bin

Now set projects as your GOPATH. Open the .bash_profile file from the $HOME folder and add the following items to the end.

nano .bash_profile

export GOPATH="$HOME/projects"
export PATH=$PATH:$GOPATH/bin

Then exit the Terminal App and open a new Terminal App. Check that the Go environment now has your new GOPATH.

go env

You should see all the Go related environment variables including GOPATH. Here are some of them:

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/you/projects"
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"


Step 4:  Get, Build and Install Basic Packages

These are Go packages you may want:

// gocode is used by many editors to provide intellisense
go get github.com/nsf/gocode

// goimports is something you should run when saving code to fill in import paths
go get golang.org/x/tools/cmd/goimports

// gorename is used by many editors to provide identifier rename support
go get golang.org/x/tools/cmd/gorename

// oracle is a tool that help with code navigation and search
go get golang.org/x/tools/cmd/oracle

// golint should be run after every build to check your code
go get github.com/golang/lint/golint


Step 5:  Debugger

Using GDB is really not an option. If you would like to experiment with Delve, here is a link:
https://github.com/derekparker/delve


Step 6: Install Editor


Sublime

http://www.sublimetext.com/

DisposaBoy wrote this plugin for Sublime
https://github.com/DisposaBoy/GoSublime

Mark Wolfe wrote this post:
http://www.wolfe.id.au/2015/03/05/using-sublime-text-for-go-development/

VIM
http://www.vim.org/download.php

Victor Farazdagi wrote this post on installing Vim for Go:
http://farazdagi.com/blog/2015/vim-as-golang-ide/

Atom
https://atom.io/

Joe Fitzgerald wrote this plugin for Atom
https://github.com/joefitzgerald/go-plus

LiteIDE

http://sourceforge.net/projects/liteide/files/

Emacs
This is the configuration Guillaume Charmes uses:
https://github.com/creack/dotfiles


Helpful Links

Here are other links to web pages that will be very helpful:

http://golang.org/
https://github.com/golang/go/wiki
https://plus.google.com/+golang/posts
http://blog.golang.org/
http://www.youtube.com/user/gocoding
http://dave.cheney.net/
http://gophervids.appspot.com/

You must watch these videos on Go Concurrency Patterns

http://www.youtube.com/watch?v=QDDwwePbDtw
http://www.youtube.com/watch?v=f6kdp27TYZs

22 comments:

  1. Debugging worked after a few additional steps to these instructions.
    1. sudo chgrp procmod /usr/local/bin/gdb
    2. sudo chmod g+s /usr/local/bin/gdb
    3. add the legacy switch -p to taskgated by modifying the file /System/Library/LaunchAgents/com.apple.taskgated.plist
    4. Force kill taskgated process (it will restart) or reboot if necessary
    5. Try again

    Solution comes from this stackoverflow thread: http://stackoverflow.com/questions/12050257/gdb-fails-on-mountain-lion

    ALERT! Be sure to use standard .plist markup with the file modification. Otherwise osx won't start next time you reboot. This happened to me. Solution to this is to reboot with recovery option (Cmd-R) and modifying the file with vi to match the standard.

    ReplyDelete
    Replies
    1. Karl, can you tell me what problems you experienced or what didn't work for you that required these steps. I would like to add these steps to the document. I didn't run into these problems. I am running version 10.8.4 of the Mac OS.

      Delete
  2. I got this error from debug console from Lite-IDE --> "Unable to find Mach task port for process-id 12383: (os/kern) protection failure (0x2).\n (please check gdb is codesigned - see taskgated(8)". This error came even though I had codesigned gdb 7.6 with the exact steps of your instructions. Now I can reproduce the error by unloading the /System/Library/LaunchDaemons/com.apple.taskgated.plist, deleting the -p switch and reloading taskgated. My Mac OS is same as yours.

    The problem has to do with codesigning, but I can't figure out in what way.

    ReplyDelete
    Replies
    1. Thank Karl, I have added the error your identified and the solution to the post

      Delete
  3. Great article! I only ran into one problem when builing and running LiteIDE test_program. "Errno 13." This is due to the gcc compiler that comes with XCode ~4.1.

    If anyone runs into Errno 13 please go here "Apple Discussion"

    ReplyDelete
    Replies
    1. Thank Alejabdro, I have added the error you identified and the solution to the post

      Delete
  4. Thanks this was a great help.
    Martyn

    ReplyDelete
  5. I ran into one small problem with the codesign command: gdb: cannot find code object on disk.
    Turns out codesign_allocate moved:
    export CODESIGN_ALLOCATE="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate"

    The locate command found it for me (as well as regular use of /usr/libexec/locate.updatedb).

    ReplyDelete
    Replies
    1. Thanks for the update. I have made the change. The latest update of Xcode changed the location. I really appreciate it !!

      Delete
  6. Thanks for the outstanding walk-through. I tripped over the nomenclature for "users" folder a couple of times, and simply guessed. Also, I was unable to get the line-8 green arrow rendered, and I have some work to do on getting the debugger working. I am using an early-1989 iMac, so darwin32-local was necessary for me to do a build; and I was using OSX 10.8.3 with the latest compatible XCode.

    Overall, really extraordinary job.

    Many thanks,

    Greg

    ReplyDelete
    Replies
    1. I did focus the article on a 64-bit architecture, sorry about that. I am glad it had enough to get you going. If you have any questions send them to me. bill@ardanstudios.com

      Delete
    2. I wrote this back when I knew nothing about the os. I fixed all the references to user directory to home. Thanks again !!

      Delete
  7. If you are into brew[0], the installation of go is dead simple[1] and I've found the upgrade process painless. GDB[2] is still a bit of a pain.

    [0] : http://brew.sh
    [1] : "brew install go gdb"
    [1] ; http://sourceware.org/gdb/wiki/BuildingOnDarwin
    https://gist.github.com/Pallinder/6426936

    ReplyDelete
  8. Thanks for this walk-through. Having an integrated debugger is my main reason for using an IDE, instead of just an editor and Make, and after this I was up and running!

    You spent a big chunk of the post fiddling with the .bashrc file and PATH variable. There's a much easier way to do this on *nix systems (including OS X): edit the /etc/paths file. In this case you want the line "/usr/local/bin" to be before "/usr/bin". And you can add an entry for /usr/local/bin if it doesn't exist.

    ReplyDelete
    Replies
    1. Thanks for the tip on the /etc/paths file. I knew about that file. Beware that debugging on the Mac using GDB is not complete, though basic debugging works.

      Delete
    2. Updated the post to use the paths file. Thanks Again !!

      Delete
  9. Ouch, that's a lot of work just to get Go installed. For me on Linux, all I had to do was run `sudo pacman -S go` (`apt-get install go` for Debian/Ubuntu users) and done, could just open up my Kate text editor and enable the built-in terminal, save the file as go source code and have go syntax highlighting, write the code and save, type go run source-code.go and done.

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Thank you very much, I only had to change one c file to work on yosemite in GDB project
    #import machine/setjmp.h to setjmp.h in gdb/darwin-nat.c. before ./configure command

    ReplyDelete
    Replies
    1. Thanks for sharing that. Can you send me that change so I can publish it :) bill@ardanstudios.com

      Delete
  12. Thanks for your shearing , my problem is like this using gdb in liteide :
    10000074^error,msg="-var-create: unable to create variable object"
    some code is ignored when I debugging step by step , could you give me some suggestions?

    ReplyDelete