Struggling with working directory

370 views
Skip to first unread message

Sayth Renshaw

unread,
Feb 11, 2017, 7:12:38 AM2/11/17
to golang-nuts
Hi All

I installed go on a new linux mint laptop and followed the standard go guide and it works fine with the hello world example.

Today i came back to work on go and cannot seem to do the install step to run my script.

sayth@sayth-E6410 ~ $ mkdir -p work/src/github.com/mortalcatalyst/xml
sayth@sayth-E6410 ~ $ code ~/work/src/github.com/mortalcatalyst/xml/xml.go
sayth@sayth-E6410 ~ $ go install github.com/mortalcatalyst/xml/xml.go
stat github.com/mortalcatalyst/xml/xml.go: no such file or directory

sayth@sayth-E6410 ~ $ cd $GOPATH    
sayth@sayth-E6410 ~/work $ go install github.com/mortalcatalyst/xml/xml.go
stat github.com/mortalcatalyst/xml/xml.go: no such file or directory

Now I am a little confused, how should I easily come in every day fire up a project and get it to work and get the file to run and install?

Cheers

Sayth

Diego Medina

unread,
Feb 11, 2017, 12:16:15 PM2/11/17
to golang-nuts
Hi,

you were very close, instead of


do



In go, you don't install the particular file, you install the program as a whole (which in many cases, it involves more than one file)

And as a side note, normally you would 

$ go install


so you don't have to specify the whole path to the project every time.

Hope that helps

P.S. as you work with Go more and more, you'll want to add these lines to ~/.bash_profile:

CDPATH=.:$GOPATH/src/github.com:$GOPATH/src/bitbucket.org #you may add more domains here if you host your proejct(s) somewhere else
export CDPATH

that let's you, form anywhere in your terminal, to type:

$ cd mor 

Then press tab and the terminal will autocomplete mortalcatalyst


Diego

Igor Maznitsa

unread,
Feb 12, 2017, 1:26:28 PM2/12/17
to golang-nuts
also you can try build golang projects through mvn-golang (with the java maven tool) in the case you should play with environment much less

Sayth Renshaw

unread,
Feb 13, 2017, 5:39:37 AM2/13/17
to golang-nuts


On Sunday, 12 February 2017 04:16:15 UTC+11, Diego Medina wrote:
Hi,

you were very close, instead of


do



In go, you don't install the particular file, you install the program as a whole (which in many cases, it involves more than one file)

And as a side note, normally you would 

$ go install


so you don't have to specify the whole path to the project every time.

Hope that helps

P.S. as you work with Go more and more, you'll want to add these lines to ~/.bash_profile:

CDPATH=.:$GOPATH/src/github.com:$GOPATH/src/bitbucket.org #you may add more domains here if you host your proejct(s) somewhere else
export CDPATH

that let's you, form anywhere in your terminal, to type:

$ cd mor 

Then press tab and the terminal will autocomplete mortalcatalyst


Diego






Hi

I now seem to have hit another problem  

sayth@sayth-E6410 ~/work/src/github.com/mortalcatalyst/xml $ go install github.com/mortalcatalyst/xml
cannot install, GOBIN must be an absolute path

An absolute path? I think somehow those directions have created a bad install.

Is there a way I can reset to defaults and is there a better install method so that I can get a clean and working environment. Keep running into errors and cannot execute code.

Cheers

Sayth

Diego Medina

unread,
Feb 13, 2017, 7:41:53 AM2/13/17
to Sayth Renshaw, golang-nuts
Can you include the link to the guide you followed to install Go?

I always follow

which is, after downloading from the link on that page,:

tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz

and then adding:

/usr/local/go/bin to the PATH 


And I have never had to set GOBIN

Thanks

Diego



--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/YE0w1Cbb1Ac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Diego Medina
Lift/Scala Consultant
di...@fmpwizard.com
https://blog.fmpwizard.com/

Sayth Renshaw

unread,
Feb 13, 2017, 5:07:54 PM2/13/17
to Diego Medina, golang-nuts

That's the one i used first but got errors that it couldn't find GOPATH even though i installed it to the suggested default location.

So when that didn't work i delete the go directory and the details from .profile and then followed ://www.digitalocean.com/community/tutorials/how-to-install-go-1-6-on-ubuntu-16-04.

Not sure why its being difficult.

Cheers

Sayth


To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Dave Cheney

unread,
Feb 13, 2017, 6:18:23 PM2/13/17
to golang-nuts, di...@fmpwizard.com
Those instructions are wrong, I've written to the author and asked them to remove the incorrect information.

Please follow the installation instructions on the golang.org website, they are well tested and known to work well. https://golang.org/doc/install

Diego Medina

unread,
Feb 13, 2017, 7:53:45 PM2/13/17
to Sayth Renshaw, golang-nuts
> Not sure why its being difficult.

knowing why I needed a GOPATH and what it was used for was probably the main issue I had when I started with Go too, some 3+ years ago, we'll help you get through it. Now, if you go back to the original instructions, https://golang.org/doc/install#install

you then just need to decide where **your** code and any code you import into your proejct(s) will be based off. Unlike many other languages where you can just start a project wherever you feel like, all Go projects start off from $GOPATH , but the regular install doesn't set this path for you (it will in 1.8). But don't worry, all it means is do this:

$ export GOPATH=/home/<your username here>/go

(you can add that to ~/.bash_profile so you don't have to do it after every reboot of your computer)

So, once you have your GOPATH environment variable ready, you can create the structure for your new project:

$  mkdir $GOPATH/src/github.com/mortalcatalyst/xml

$ write some awesome code now in here
$ go install # note that you do not need to specify the path to your project, because you are already inside your project root folder

and at this point you are ready to use your new cool app :)

If any of these instructions don't help or give you an error, post back what you got.

Thanks

Diego






To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Diego Medina
Lift/Scala Consultant
di...@fmpwizard.com
https://blog.fmpwizard.com/

Sayth Renshaw

unread,
Feb 19, 2017, 1:27:31 AM2/19/17
to golang-nuts, flebbe...@gmail.com, di...@fmpwizard.com
Thanks Diego

Did get it working (1.8) on windows though a side note on Docs for Fedora that putting the path in $HOME/.profile does not work and for me anyway I needed to put it in .bashrc

Also an note with system wide with fedora is that for system wide it should be a custom .sh script in /etc/profile.d well according the the etc/profile anyway.
From etc/profile

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.



Thanks 

Sayth 

Diego Medina

unread,
Feb 19, 2017, 7:06:27 AM2/19/17
to Sayth Renshaw, golang-nuts


Did get it working (1.8) on windows though a side note on Docs for Fedora that putting the path in $HOME/.profile does not work and for me anyway I needed to put it in .bashrc




Great to know you got it working!

re adding the CDPATH and GOPATH/bin , I wrote ~/.bash_profile, not ~/.profile  . Tested on Fedora 23, 24 and 25
 



Regards,

Diego

Also an note with system wide with fedora is that for system wide it should be a custom .sh script in /etc/profile.d well according the the etc/profile anyway.
From etc/profile

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.



Thanks 

Sayth 
Reply all
Reply to author
Forward
0 new messages