The first taste of the Raspberry Pi development Go language

Source: Internet
Author: User
Tags aliyun win32diskimager
This is a creation in Article, where the information may have evolved or changed.

Recently turned up the Raspberry Pi I bought before, and decided to pick up the Raspberry Pi combined with the go language that I was learning to engage in things. Here first build the environment to run the GO program.

First, the Raspberry Pi installation

Environment: Raspberry PI 3 B, WIN10, 16G CLASS10 TF card, card reader, Advanced IP Scanner, Mobaxterm, go1.8.3.linux-armv6l.tar.gz

Raspberry Pi is a system that starts directly on the SD card, there is a 16GB tf card, a card reader, connected to the computer. Download a software Win32diskimager on your computer. And to the Raspberry Pi official website to download a new image file, RASPBIAN STRETCH LITE. This is because I don't have an extra monitor, I use the latest image file directly.

The above are ready to use Win32diskimager to burn the above img file to the SD card, here should be careful not to choose the wrong partition . Burn it. Open My Computer to find the BOOT partition on the TF card and create a new ssh -named file in it (the Raspberry Pi does not open SSH by default, which allows it to open SSH by default).

Now you can start the Raspberry Pi, plug in the network cable to the router, on the router can see the Raspberry Pi IP. But because I am a switch here and there were a lot of devices last time, I used the IP scan tool advanced IP Scanner. After the scan can see my Raspberry Pi IP is 192.168.77.140


Advanced IP Scanner.png

After you find the IP, you can log in using SSH (default account: Pi default password: raspberry). Here my SSH software use is mobaxterm very powerful, give an example is: Login SSH when the default will also be next to open sftp, can directly drag files, very convenient.


Mobaxterm_sftp.png

Second, the Raspberry Pi configuration

The Raspberry Pi log in using SSH and then need to configure the first, here is the most basic configuration:

2.1 Password Modification

Use the following command to modify the initial password. You need to follow the prompts to enter the original password, and then enter the new password two times.

passwd

2.2 Modifying the default source

The default source for the Raspberry Pi is abroad, which may be slower when used domestically, where the source is modified to the source provided by Aliyun . To facilitate my first installation of the Vim software, because it is not used to the Raspberry Pi with the VI software.

sudo apt-get updatesudo apt-get install vim -y

Then make changes to the source:

sudo vim /etc/apt/sources.list//注释掉原来的源//然后添加以下源deb http://mirrors.aliyun.com/raspbian/raspbian/ stretch main non-free contrib rpideb-src http://mirrors.aliyun.com/raspbian/raspbian/ stretch main non-free contrib rpi//这里因为下载的系统是 RASPBIAN STRETCH LITE 所有我这里使用了 stretch 源。

It can be updated directly after saving:

sudo apt-get updatesudo apt-get upgrade -y

To the simple configuration of this system has been completed.

Third, the Go installation

At the time of writing, the latest version of Golang is 1.8.3 , which also provides the arm version of the binary package, which can be downloaded go1.8.3.linux-armv6l.tar.gz on the website below.

After the download is ready, you can install the test, first the compressed packet into the Raspberry Pi. Here I use the mobaxterm's sftp, which is very handy to drag in.
After entering the appropriate directory:

tar -C /usr/local -zvxf go1.8.3.linux-armv6l.tar.gz

Then modify the environment variables, here I lazy directly modify the system.

sudo vim /etc/profile//在文件末尾添加如下内容export PATH=$PATH:/usr/local/go/bin

Then reboot the Raspberry Pi.

sudo reboot//不重启也行,使用source 命令应用修改source /etc/profile

Here you can try to see if the go is installed. Enter go return in bash, and if you output a bunch of things instead of missing files, you're ready to install them.

Four, the experiment

After the environment has been installed, you can try to run the Go program, write the following code:

package mainimport "fmt"func main(){    fmt.Printf("hello world\n");}

Save as Main.go file. Typing the following command:

go build main.gostrip main -o main1ls -al

Finally we see the directory appeared in three files, main main1 main.go, see the file after the discovery of the compilation generated files is really big, good guy so direct 1M more. After the strip there is also about 900K. Run below to see if it is correct.

./main./main1

Normal output, nothing wrong.


Mobaxterm_result.png
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.