79 lines
1.6 KiB
Markdown
Raw Normal View History

# Cheatsheet: Write your First Go Program
2019-05-15 23:39:54 +03:00
Hi!
For reference, you can store this cheatsheet after you take the lectures in this section.
You can also print this cheatsheet and then follow the video lectures in this section along with it.
Enjoy!
---
## COMMAND LINE COMMANDS:
* Enter into a directory: `cd directoryPath`
* **WINDOWS:**
* List files in a directory: `dir`
* **OS X & LINUXes:**
* List files in a directory: `ls`
2019-05-15 23:39:54 +03:00
## BUILDING & RUNNING GO PROGRAMS:
* **Build a Go program:**
* While inside a program directory, type:
* `go build`
* **Run a Go program:**
* While inside a program directory, type:
* `go run main.go`
## WHERE YOU SHOULD PUT YOUR SOURCE FILES?
* In any directory you like.
## FIRST PROGRAM
### Create a directory
* Create a new directory:
* `mkdir myDirectoryName`
* Go to that directory:
* `cd myDirectoryName`
2018-10-30 23:32:05 +03:00
### Add the source code files
* Create a new `code main.go` file.
* This is going to the create the file in the folder, and open up it in the Visual Studio Code.
2018-10-30 23:32:05 +03:00
* And add the following code to it and save it.
```go
package main
import "fmt"
func main() {
fmt.Println("Hi! I want to be a Gopher!")
}
```
### Run the program
* Finally, return back to the command-line.
* Run it like this: `go run main.go`
* If you create other files and run them all, you can use this command:
* `go run .`
That's all! Enjoy!
> For more tutorials: [https://blog.learngoprogramming.com](https://blog.learngoprogramming.com)
2018-11-18 05:03:43 +08:00
>
> Copyright © 2018 Inanc Gumus
2018-11-18 05:03:43 +08:00
>
> Learn Go Programming Course
2018-11-18 05:03:43 +08:00
>
> [Click here to read the license.](https://creativecommons.org/licenses/by-nc-sa/4.0/)