1

I'm new to golang and I'm trying to write a program using this tutorial.

However I'm getting this error thrown while compiling it.

6g: command not found

Here's what I've tried:

$ go version
go version go1.4.1 darwin/amd64
  • I've set environment variables properly

Here's how my .bashrc looks like:

 $ tail ~/.bashrc

export GOBIN=/Users/abhijeet/code/golang/go/bin  
export GOROOT=/Users/abhijeet/code/golang/go  
export GOPATH=/Users/abhijeet/code/golang/gopath  
export GOOS="darwin"  
export GOARCH="amd64"  
export PATH="$GOBIN:$PATH"
  • I've added below line under /etc/profile to source it

Here's how it looks:

[ -r $HOME/.bashrc ] && source $HOME/.bashrc
  • If I quit the terminal, launch it again and echo any of the variables, they work.

  • I have gcc installed.

Here's what I get when I run "gcc --version" command:

$ gcc --version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
  • If I write any other go program and run it, it works. For instance, all the programs from section 1 through 5 from here, and till the "Go Templates - Part 3 - Template Sets" work just fine even now. Only this particular tutorial is troubling me.

  • None of the other programs I just gave link to, required me to run the "6g" command. But they still run on my machine.

  • About the line where I get error, I am using the right one to reflect folder names in my machine.

What they've asked to run:

6g -I $GOPATH/pkg/linux_amd64 urlshortener.go

What I'm running:

6g -I $GOPATH/pkg/darwin_amd64 urlshortener.go
  • Important: I have followed all the steps in the tutorial for using external apis. However, if I look inside the darwin_amd64 folder, I don't see any urlshortener.go file at all!

All I can find is

darwin_amd64
├───code.google.com
│   ├───p
│   │   └───google-api-go-client
│   │       └───googleapi
│   │       │    └─── <more folders and files here>
│   │       └───urlshortener 
│   │       │   └───v1.a
│   │       └───googleapi.a
│   │ 

So I know there's some problem there, but I also know that this probably isn't what is causing the error I'm seeing, otherwise I would have seen the error like "file not found". I just wanted to mention it as an additional data.

So I appreciate any help on this. Please let me know if I should provide any additional data as well.

Grokify
  • 15,092
  • 6
  • 60
  • 81
Abhijeet
  • 25
  • 1
  • 5
  • 1
    Important: Never set or export GOROOT, it should not be used for normal go tool usage. – Volker Feb 19 '15 at 15:05
  • Thanks @Volker! But can you also elaborate a bit on the reason for that? – Abhijeet Feb 19 '15 at 16:13
  • The GOROOT is compiled into the go tool. Setting GOROOT is cargo cult from the early days if Go. – Volker Feb 19 '15 at 20:30
  • The tutorial is outdated, 6g is not intended to be used separately, you should use the `go` command – OscarRyz Feb 20 '15 at 00:44
  • Further, you actually only want to set `GOPATH`, don't set **any** other `GO`* environment variables unless you know exactly what you're doing. – Dave C Feb 22 '15 at 00:06

1 Answers1

2

It's an internal command, you can run it with go tool 6g.

That being said, that guide is extremely outdated and not relevant anymore.

  • To compile I used: 6g -I $GOPATH/pkg/linux_amd64 urlshortener.go
  • To link I used: 6l -L $GOPATH/pkg/linux_amd64 urlshortener.6

Is replaced with simply running go build urlshortner.go or even go run urlshortner.go

Few resources to check:

OneOfOne
  • 95,033
  • 20
  • 184
  • 185
  • 1
    Thank you! I thought the tutorial gave me the right flow when learning Go. I'll follow the other resources you've given too. (P.S. : I can't up vote your response because I'm still new and don't have enough reputation points.) – Abhijeet Feb 19 '15 at 14:18