Setup development environment on Windows: WSL2 + Go + VSCode + Docker + Make + Sqlc

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello guys and welcome to the backend master class! In this video, we will learn how to install WSL and use it to set up a Golang development environment on Windows. WSL stands for Windows Subsystem for Linux It lets us run a Linux environment directly on Windows. So it is very convenient for us to develop applications, Especially the ones that will finally be deployed to a linux platform. To install WSL, we’ll need to open a PowerShell in administrator mode, then run this simple wsl install command. OK, so now WSL has been installed, But as it said here, the changes will not be effective until we reboot the computer. But before doing that, let’s go through this doc a bit to see if there’s something else we should pay attention to. First, you might notice that, Ubuntu is installed by default, But it’s possible to change to another Linux distro if you want. Here it also said that we need to create a user account for the installed Linux distribution. I guess it will ask us to do that after we restart the machine. One thing I would like to do before we restart is, Setting up the Windows Terminal, to give it a better and more professional look. So let’s follow this link to learn how to do that. OK so it redirects us to this Microsoft app page, And somehow it detects that I’m in France and automatically showing French texts here. This button basically says that we can get it from the application store. When you click on the button, it will send you to the the Microsoft Store, And all we have to do is click “Open”. And that’s it, the windows terminal has been installed. You can see that it has a different look than before. I believe we can also customize the theme to make it look more beautiful. But that’s not the focus of this video. So I’ll let you do that on your own if you want. Next, I’m gonna restart the computer. OK so after restarting, a new terminal will show up on the screen, It launches Ubuntu, and asks us to create a default UNIX user account. So let’s enter the username, the password, and confirm that password one more time. And we’re done! Ubuntu is successfully installed. We are now inside a Linux shell. So let’s try running some Linux commands, such as pwd or ls. They’re all working well. Let’s check if there’s a “make” command or not, Since we’re gonna use it a lot for development. So it seems “make” is not installed by default, But we can easily install it using apt install. First, let’s run “sudo apt update” Then, we can install make with this command: “sudo apt install make” After it’s done, if we run “make -version”, it will show us the installed version. OK, so now we can comfortably use this Linux shell for development. But I wonder, how can we start a new Linux shell? Let’s try using this box to search for Terminal, and open it. OK, so it does open a new terminal, However, it’s just a normal Windows PowerShell, not a Linux shell. In order to open a Linux shell, we must search for “Ubuntu” instead. Once we open this app, the terminal will start, but this time, with a Linux shell as we wanted. So now, the linux environment is ready. Let’s move to the next step: install golang. I’m gonna open a new Ubuntu terminal shell. And run this command to install golang: “sudo snap install go --classic” Enter the password for your Linux user that you set up earlier And voilà, the latest version of Golang has been installed. It is Go 1.21.1 at the time I recorded this video. Next, let’s install “sqlc”, because we’re gonna use it a lot to generate Golang codes from SQL queries. Just run “sudo snap install sqlc”. And that’s it! Sqlc has been successfully installed. Now it’s time to install Visual studio code. It’s a very powerful IDE for programming in Go and many other languages. I’m gonna open the Microsoft Store and search for vscode. Then click this button to install it. Alright, vscode has been installed, so let’s open it. The first time you open vscode, it will ask you to Install the WSL extension. If you don’t see this message show up, you can use the extension tab to search and install it on your own. This extension is very important because it allows us to interact with the Linux environment that we set up earlier. Another extension that you should install is the “Go” extension. It will add language support for Golang to vscode. OK, now the last thing we need to complete the development environment is Docker. On Windows, we should install Docker Desktop, which will support WSL backend out of the box. There are some requirements for the minimum version of WSL and Windows. I’m using Windows 11 Pro with the latest version of WSL, so let’s go ahead and download the latest version of Docker Desktop for Windows. The next step is to open the downloaded file to install it. But you should stop here, and don’t do that yet. Because I’m gonna show you, Why doing that will cause several issues later. OK, the installation is completed, and I need to restart. So after restarting the computer, the Docker Desktop app will show up. And it seems to be working well with the WSL based engine. But let’s open the terminal and do some tests. First, let’s run “docker ps” OK, it’s working. But when I try to run “go version”, it suddenly returns a strange error. We didn’t get this error when we ran the same command earlier, when installing go. So this is definitely something caused by Docker Desktop. I googled this error message, and found this github issue page. Many people are facing the same problem, And it seems the only way to fix it is to reinstall Docker Desktop on a different folder. OK, let me uninstall it first. We have to quit the application, Then search for it in this box, and click “Uninstall” It will bring us to this Programs and Features window. Then we have to look for Docker Desktop again, Right-click the app, and select “Uninstall” Wait a bit, and the app is now uninstalled successfully. Now, to reinstall the app to other location, we have to run a command in a PowerShell. On this page, make sure you scroll down and find the right comment on June 19. I tried several other commands, but only this one worked. So let’s copy it, And start a Windows PowerShell as administrator. Now we have to change the current directory to the Downloads folder, because it’s where the Docker Desktop installer is saved. OK, the file is here, so we can run the copied command. After the installation completes, we’ll have to restart the computer, just like before. Once you’ve restarted, we can open the Docker Desktop app. And in the settings, make sure you check this box to “Use the WSL based engine”. I also check the box to add the docker internal name to the etc/hosts file since it will be useful to allow communication between the container and the host machine. Alright, now, let’s open a new Ubuntu terminal to check if everything is working well or not. The “docker ps” command is still working, as expected. Let’s try running “go version”. This time, there’s no errors. So we’re now done with the development environment setup on Windows. I hope you have learned something new and interesting in this video. Thanks a lot for watching! Happy learning, and see you in the next lecture!
Info
Channel: TECH SCHOOL
Views: 13,275
Rating: undefined out of 5
Keywords: wls2, wsl, windows linux, windows ubuntu, windows golang, windows vscode, windows docker, windows makefile, windows make, windows sqlc
Id: TtCfDXfSw_0
Channel Id: undefined
Length: 9min 15sec (555 seconds)
Published: Fri Sep 22 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.