go on Windows 10 from the bash shell (and the cmd shell)

1,398 views
Skip to first unread message

Pat Farrell

unread,
Oct 11, 2017, 1:04:28 AM10/11/17
to golang-nuts
I've installed the go 1.9 binary distribution on my windows 10 laptop. 
I just let the install do the defaults. (in addition to learning go, I'm trying to see if I can live with 
bash under Windows, or if I have to reboot to a linux distro to avoid going crazy, that is a separate topic)

in the cmd shell
'go build' works, but creates a file go.exe that when run, displays hello world
it does not create the expected hello.exe

in the bash shell, 'go build' does not work, it whines that 'go' is not a program

The program 'go' is currently not installed. You can install it by typing:
sudo apt-get install gccgo-go


but 'go.exe build' does create a local go.exe which executes and displays the expected hello world.

Which raises a couple of questions:

1) is the standard documentation wrong/out of date?
2) how do I get the go build process to create a hello.exe rather than go.exe?
3) how do I get the bash shell to let me just type 'go build' like we all want?



as

unread,
Oct 11, 2017, 3:08:26 AM10/11/17
to golang-nuts
A Go project is organized as a file system. The directory your go source files reside in indicate the name of the executable created with go build.

brainman

unread,
Oct 11, 2017, 4:12:45 AM10/11/17
to golang-nuts
> On Wednesday, 11 October 2017 16:04:28 UTC+11, Pat Farrell wrote:

> 1) is the standard documentation wrong/out of date?

What documentation are you referring to? Did you read https://golang.org/doc/code.html ?


> 2) how do I get the go build process to create a hello.exe rather than go.exe?

I suspect Go uses your current directory to name your output file. Read https://golang.org/doc/code.html how to organize your Go code. You could also use -o flag to provide whatever output file name you like, for example "go build -o hello.exe".

> 3) how do I get the bash shell to let me just type 'go build' like we all want?

What bash shell are you talking about? Windows does not come with bash shell. If you have Linux install, then you should install Linux version of Go, not Windows version of Go.

I hope it helps.

Alex

Wojciech S. Czarnecki

unread,
Oct 11, 2017, 7:35:59 AM10/11/17
to golan...@googlegroups.com
On Wed, 11 Oct 2017 01:12:45 -0700 (PDT)
brainman <alex.b...@gmail.com> wrote:

> What bash shell are you talking about? Windows does not come
> with bash shell.

Ooops, now it comes:
https://msdn.microsoft.com/en-us/commandline/wsl/about.

> If you have Linux install, then you should install Linux version of
> Go, not Windows version of Go.

OP got this hint from the Windows (> sudo apt-get install gccgo).
This is a new scenario for beginners and Go docs are not aware of it.

--
Wojciech S. Czarnecki
<< ^oo^ >> OHIR-RIPE

Pat Farrell

unread,
Oct 11, 2017, 11:34:49 AM10/11/17
to golang-nuts
On Wednesday, October 11, 2017 at 4:12:45 AM UTC-4, brainman wrote:
> On Wednesday, 11 October 2017 16:04:28 UTC+11, Pat Farrell wrote:
> 1) is the standard documentation wrong/out of date?

What documentation are you referring to? Did you read https://golang.org/doc/code.html ?



 
> 2) how do I get the go build process to create a hello.exe rather than go.exe?

I suspect Go uses your current directory to name your output file. Read https://golang.org/doc/code.html how to organize your Go code. You could also use -o flag to provide whatever output file name you like, for example "go build -o hello.exe".

I'll try that.
 
> 3) how do I get the bash shell to let me just type 'go build' like we all want?

What bash shell are you talking about? Windows does not come with bash shell. If you have Linux install, then you should install Linux version of Go, not Windows version of Go.

You are way out of date on this one. After decades of providing a terrible shell, Microsoft has decided to provide a real bash shell with real Ubuntu utilities.   It has apt-get and is pretty nice, way better than the old cmd shell

Still need to figure out how to make a simple 'go build' work
rather than having to enter 'go.exe build' all the time

Tamás Gulácsi

unread,
Oct 11, 2017, 1:02:35 PM10/11/17
to golang-nuts
WSL is a (nice) hack with rough edges: you can invoke Windows applications (go.exe) from that bash, or install the Linux go under WSL, and have "go" as under Linux.

brainman

unread,
Oct 11, 2017, 6:08:26 PM10/11/17
to golang-nuts
> On Thursday, 12 October 2017 02:34:49 UTC+11, Pat Farrell wrote:
>
> https://golang.org/doc/install

This one says "... Next, make the directory src/hello inside your workspace ...". And, I take it, you skipped that step.

> ... Microsoft has decided to provide a real bash shell with real Ubuntu utilities. It has apt-get and is pretty nice, way better than the old cmd shell
https://msdn.microsoft.com/en-us/commandline/wsl/about

If you want to use WSL, then you should treat it as Linux (because it is not Windows). So you should install Linux version of Go on WSL, not Windows version. And WSL is not supported by Go yet (see https://github.com/golang/go/issues/16628 for details).

Pat Farrell

unread,
Oct 11, 2017, 6:28:42 PM10/11/17
to golang-nuts

On Wednesday, October 11, 2017 at 6:08:26 PM UTC-4, brainman wrote:
> On Thursday, 12 October 2017 02:34:49 UTC+11, Pat Farrell wrote:
> https://golang.org/doc/install

This one says "... Next, make the directory src/hello inside your workspace ...". And, I take it, you skipped that step.

Yes, I didn't understand what a "workspace" is. Still don't know what that buzzword means. So I created a directory in my sandbox called 'go'
and got go.exe


 
> ... Microsoft has decided to provide a real bash shell with real Ubuntu utilities. It has apt-get and is pretty nice, way better than the old cmd shell
https://msdn.microsoft.com/en-us/commandline/wsl/about

If you want to use WSL, then you should treat it as Linux (because it is not Windows). So you should install Linux version of Go on WSL, not Windows version. And WSL is not supported by Go yet (see https://github.com/golang/go/issues/16628 for details).


That thread is at least a year old. Back then it was in Beta from MS. Its released now.

I know, almost all developers use either OS-X or a Linux for development. I did too when I did it full time.
But I'm trying to learn go and while I have three or four Linux machines and an OS-X one, my day to day
laptop is Windows because I need Lightroom, Photoshop and Premier, and I am tired of paying for Apple's over priced, under
performing laptops.

Go is claimed to be cross platform, and the language sure looks to be that way. But the installation instructions
on Windows seem to be an afterthought and fairly out of date. I wish the world's desktops were not Windows, but 
I'm not in charge of that.

I'm surprised that the default Windows binary installation still installs the gnu / cygwin stuff
which has never "supported" anything.


 
I hope it helps.

The information does. Thanks
 
If there needs to be tips or hints about which go setup to use on Windows, that sounds good to me.
Maybe even a discussion of why you would want to use one approach (with cygwin) against another (using WSL)

brainman

unread,
Oct 11, 2017, 7:59:04 PM10/11/17
to golang-nuts
On Thursday, 12 October 2017 09:28:42 UTC+11, Pat Farrell wrote:

> Yes, I didn't understand what a "workspace" is. Still don't know what that buzzword means.

I suggested you read https://golang.org/doc/code.html - it should answer your question. But if you prefer me explaining it (and I am not as good as people who wrote the doco), when you write programs with Go all your source code, compiled packages and final binaries will be stored inside of single directory on your computer. It is up to you to decide where that directory is, but all Go tools would expect to find that directory path in GOPATH environment variable. All your source files have to be stored under %GOPATH%\src, all compiled packages will go into %GOPATH%\pkg and all compiled binaries will be installed into %GOPATH%\bin. So, if you do
```
set GOPATH=c:\gopath
```
then create this file
```
c:\gopath\src\hello>type main.go
package main

import "fmt"

func main() {
        fmt.Println("Helle")
}

c:\gopath\src\hello>
```
in c:\gopath\src\hello directory and then run "go install hello" command, it will create c:\gopath\bin\hello.exe with your program. "go install" and "go build" commands do not care about source file names, they care about package names, and package name is determined by the directory where your source files are stored. For example the same file could be copied into c:\gopath\src\a\b\c\alex directory, and then you would have to do "go install a/b/c/alex" to build and install it, and that would create c:\gopath\bin\alex.exe executable.

Hopefully this will get you started, but there is much more to Go tools. You should start learning by reading https://golang.org/doc/code.html

> So I created a directory in my sandbox called 'go' and got go.exe

Yes. "go build" command uses directory name to decide what the package name is, and therefore what the output binary will be called. You could use -o flag to override that, but you should try and live by Go conventions first, you might discover that these work for you.
 
> That thread is at least a year old. Back then it was in Beta from MS. Its released now.

Sure. But Go is still not supported on WSL. There were few issues reported about Go on WSL (you could search https://golang.org/issue ). Some of them are quite basic, like deleting all files in a directory does not delete all files. If you want to use development environment with bugs, then sure, you could do that. Just start here https://golang.org/doc/install but use Linux instructions, not Windows instructions.

> But I'm trying to learn go and while I have three or four Linux machines and an OS-X one, my day to day laptop is Windows because I need Lightroom, Photoshop and Premier, and I am tired of paying for Apple's over priced, under performing laptops.

Go works pretty much the same on any OS (bar file paths and couple of small things). Same commands, same tools. You can build any Go program on any OS for any OS (except when your program uses any libraries written in C). So whatever OS you prefer is fine. Some people use Plan 9 to develop in Go.

> Go is claimed to be cross platform, and the language sure looks to be that way. But the installation instructions on Windows seem to be an afterthought and fairly out of date.

It is hard for me to judge (I have used Go for many years). If you think you could improve the documentation, you are welcome to contribute https://golang.org/doc/contribute.html

> I'm surprised that the default Windows binary installation still installs the gnu / cygwin stuff which has never "supported" anything.

Go, its libraries and tools are written in Go. So Go installation does not installs any gnu / cygwin stuff. Give me an example, if you know otherwise.

Alex

Pat Farrell

unread,
Oct 11, 2017, 8:23:08 PM10/11/17
to golang-nuts
I found how to force 'go build' to work under the bash shell on Winderz
you have to add a symlink in the program directory containing go.exe
such as 
    ln -s go.exe go


On Wednesday, October 11, 2017 at 7:59:04 PM UTC-4, brainman wrote:
On Thursday, 12 October 2017 09:28:42 UTC+11, Pat Farrell wrote:
> Yes, I didn't understand what a "workspace" is. Still don't know what that buzzword means.

I suggested you read https://golang.org/doc/code.html - it should answer your question.

I saw you write that. But there was nothing that told me why.
I started at golang.org and have been following the instructions.
There was no reference to this document in any of the installation instruction pages.

Again, it looks like someone who hated Windows (and I hate Windows as much as any other developer) 
was forced to implement it and wrote the minimal documentation they could. They did this long ago, and no one has updated it



|| when you write programs with Go all your source code, compiled packages and final binaries will be stored inside of single 
|| directory on your computer. 

Seriously? That sure seem like bad practices to me. Nearly all the code I've worked on over the past 40 years was too big to go into a single directory.



```
set GOPATH=c:\gopath
```

Which is a Linux-type instruction. Doesn't work on Windows


 
> That thread is at least a year old. Back then it was in Beta from MS. Its released now.

Sure. But Go is still not supported on WSL.

That is a bug.

 
 If you want to use development environment with bugs, then sure, you could do that. 

I'm sorry, this attitude is not helpful.




> Go is claimed to be cross platform, and the language sure looks to be that way. But the installation instructions on Windows seem to be an afterthought and fairly out of date.

It is hard for me to judge (I have used Go for many years).

Clearly you have not tried to start with zero knowledge on windows.
I'm sure its much easier if you use a prefered OS such as Linux.


Go, its libraries and tools are written in Go. So Go installation does not installs any gnu / cygwin stuff.

The installation for binaries uses some standard Windows installation tool, been the same since about Windows 95.
Its clearly not written in go

Perhaps once I get this all working, I'll see the native go tools and libraries. But I'm not there yet.

I have now been dorking around on this for a couple of days. If I was not intrigued about how great go would be, I'd have stopped already. Something that I randomly clicked on to make this work started a cygwin shell. I have no idea what. Nor do I know what installed it.

I'd rather that this remain unanswered until someone who has active knowledge about what is happening with the go on Windows installation can chime in.

Thanks
Pat

brainman

unread,
Oct 11, 2017, 8:55:58 PM10/11/17
to golang-nuts
On Thursday, 12 October 2017 11:23:08 UTC+11, Pat Farrell wrote:
> ... But there was nothing that told me why.

Are you asking me why all your Go code should live inside of single directory? Hopefully others will reply. But I think it is because Go does not use any config files to build programs. There are no "project files" or "Makefile" or whatever. Go tools use your directory structure to work out how to build things.

> Again, it looks like someone who hated Windows (and I hate Windows as much as any other developer) was forced to implement it and wrote the minimal documentation they could. They did this long ago, and no one has updated it

That is what we have. If you think you can make it better, feel free to contribute or at least report an issue at https://golang.org/issue

> Seriously? That sure seem like bad practices to me. Nearly all the code I've worked on over the past 40 years was too big to go into a single directory.

Well Go tools put everything under GOPATH.

> Which is a Linux-type instruction. Doesn't work on Windows

`set GOPATH=c:\gopath` works for me on Windows. On Linux you want something like `export GOPATH=/home/alex/gopath` (this depends on what shell you use).

>> Sure. But Go is still not supported on WSL.
> That is a bug.

Yes, it is a bug. I hope Microsoft are working on fixing these.
 
>> If you want to use development environment with bugs, then sure, you could do that. 
>
> I'm sorry, this attitude is not helpful.

I did not intend to offend you, I apologize if I did. I just stated the fact that WSL is too buggy to be used for development (in my opinion). But you are free to use whatever tools you like.

> The installation for binaries uses some standard Windows installation tool, been the same since about Windows 95. Its clearly not written in go

Or yes. Go installation program (like many others on Windows) is built using "WiX Toolset". But you don't even have to use that. You can just download Go as a zip file (search for "Zip archive" on https://golang.org/doc/install )

> I have now been dorking around on this for a couple of days.

I think you are making things harder for yourself by trying to mix 2 new things at the same time: Go and WSL. I suggest you try and use Linux version of Go on your Linux computer or use Windows version of Go on your Windows computer. These scenarios are very common and people will quickly help you with that.

Alex

bnix...@gmail.com

unread,
Oct 11, 2017, 11:59:47 PM10/11/17
to golang-nuts
Did you install the Windows or Linux go binary distribution?

Sounds like you might have installed the Window distribution and running it in bash?

I installed the Linux go distribution and it worked just fine. I think I created a symlink from /usr/local/go/bin/go to /usr/local/bin/go, or you can alter your $PATH to include /usr/local/go/bin so you get access to go, good, and gofmt.

Pat Farrell

unread,
Oct 12, 2017, 12:04:05 AM10/12/17
to Bill Nixon, golang-nuts
On Wed, Oct 11, 2017 at 11:32 PM, <bnix...@gmail.com> wrote:
Did you install the Windows or Linux go binary distribution?

I went to the distribution site and installed the .msi file
like any windows installation

I've been running bash since about 1987, so I'm partial to it.

Other than the file names, I'm not convinced that there is any actual difference
between the go.exe you get with the MSI and the go binary that apt-get installs

I've got it running now, but I am not sure exactly what I did to get it all working (altho the symlink was obvious)

Bill, between you and I, we have 70+ years experience at this, you'd think we could get a compiler installed.

Brian Ketelsen

unread,
Oct 12, 2017, 5:20:47 AM10/12/17
to golang-nuts
WSL works perfectly well for Go development. It’s my primary dev environment Just treat it like Linux and you’ll be fine.

Gerald Henriksen

unread,
Oct 12, 2017, 8:31:52 PM10/12/17
to golang-nuts
On Thu, 12 Oct 2017 00:03:41 -0400, you wrote:

>Other than the file names, I'm not convinced that there is any actual
>difference
>between the go.exe you get with the MSI and the go binary that apt-get
>installs

There is a difference.

The MSI is a Windows application, whereas apt-get would install the
Linux binary of go.

WSL has you actually running Linux binaries on Windows unless you
specifically go and choose a Windows executable.

Pat Farrell

unread,
Oct 13, 2017, 1:08:44 AM10/13/17
to golang-nuts

On Thursday, October 12, 2017 at 8:31:52 PM UTC-4, Gerald wrote:
The MSI is a Windows application, whereas apt-get would install the
Linux binary of go.

WSL has you actually running Linux binaries on Windows unless you
specifically go and choose a Windows executable.

The MSI file triggers a Windows application, sure. But is the actual go binary different?
Its possible to make a Posix compliant system call on nearly any operating system. Posix was
designed to let the US Government require Unix, back when Unix was special. But the basic functions
that most of us call Unix or Linux system calls are trivial in any operating system. Probably even Plan-9

There is a lot less to making bash, and apt-get run on any operating system than many folks think

I may have to do both installs and do a shasum on the files.
 

Sotirios Mantziaris

unread,
Oct 13, 2017, 2:23:18 PM10/13/17
to golang-nuts
follow the procedure of installing go in linux.
set the following in .bashrc of your home directory at the end:

export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$GOPATH/bin

worked for me just fine!

Gerald Henriksen

unread,
Oct 13, 2017, 5:10:50 PM10/13/17
to golan...@googlegroups.com
WSL actually runs the Linux distrobution you choose - currently SUSE
and Ubuntu are available with Fedora coming.

The only limitation is no GUI stuff.

Microsoft enables this by amongst other things emulating the Linux
kernel so that WSL natively runs Linux ELF64 binaries.

So Go installed via the Windows MSI and via apt-get (or yum or dnf)
will be entirely separate binaries.

More information:

https://msdn.microsoft.com/en-us/commandline/wsl/faq

https://blogs.msdn.microsoft.com/wsl/2016/04/22/windows-subsystem-for-linux-overview/


jo...@venegaslittman.com

unread,
Oct 17, 2017, 12:46:28 PM10/17/17
to golang-nuts
just a heads up regarding Ubuntu Bash Shell on Windows10: if you open the Ubuntu Bash Shell and type the command: "lsb_release -a" you might discover it  is running Ubuntu 14.04 you might want to run an upgrade to Ubuntu 16.04 which is now available. See the following for installation details.

how-to-update-the-windows-bash-shell  <== BTW the instructions here forgot to include necessary fonts for Xserver if you want to install x11-common. Just include  "xfonts-*"

The quickest method of upgrading to Ubuntu 16.04  is a two step process: [1] enter windows cmd.exe: "lxrun uninstall" then "lxrun install"


Oh I installed Xming/Xlauncher to my Windows10 Apps and I can use it as an Xserver for both Putty and Ubuntu 16.04 Bash Shell.

IMPORTANT: The sender intends that this electronic message is for the exclusive use of the person to whom it is addressed. This message may contain information that is confidential. If the reader of this message is not an intended recipient, be aware that any disclosure, dissemination, distribution or copying of this communication, or the use of its contents, is prohibited. If you have received this message in error, then please immediately notify the sender of your inadvertent receipt and delete this message from all data storage systems. 
Reply all
Reply to author
Forward
0 new messages