Jump to Content
Compute

Let's build a Linux virtual machine

April 24, 2023
Laurie White

Developer Relations Engineer

Let's build a Linux virtual machine

Creating a virtual machine (VM), a computer you can use without needing to purchase, set up, or keep around, is one of the most basic functions of the cloud.  You can rent as many computers as you need and delete them when you're done with them.


But VMs are only a benefit if setting up a virtual machine is easy.  In Google Cloud, creating a VM is done with the Compute Engine service.  There's a short (probably under 5 minute) interactive tutorial to get you started.  I'll explain what's going on in that tutorial here, but you should walk through the tutorial as well to see all of the exact steps.


Once you've finished this tutorial, be sure to check the references to learn more about creating and using VMs.

Selecting a project

Everything in your application will be in a project, so you'll either need to create or select a project to do this tutorial in.  Projects need to be associated with a billing account, so if you don't have one, consider signing up for the Free Trial.  You'll start in the Cloud Console.

Enabling APIs

Normally you will go to APIs and services from the Navigation menu to enable the Compute Engine API, but the tutorial will let you do this by just clicking a button.  If you've already enabled the Compute Engine API for a project, you won't need to enable it again.

Creating a VM

In this tutorial, you'll create a Linux VM.  (Don't worry; if you want a Windows VM, there's a tutorial for that too!)  From the Navigation menu, select Computer Engine.  By default, you'll go to the first item in the submenu, which is VM instances.  


You can then click Create instance to create a new VM.  You'll notice there are a lot of options, allowing you to change the name, the machine configuration, the boot disk, and far more.  As you change options, notice how the price for the VM changes in the upper right of the screen. 

https://storage.googleapis.com/gweb-cloudblog-publish/images/Figure_1_VM_Options-page_1.max-1200x1200.jpg

Figure 1-Some of the many VM options available

The tutorial will give you suggested changes to make to change the operating system and allow HTTP traffic.  These options can be seen further down the options screen, as shown in Figure 2.  It will also help you find the right places to enter this information--the first time you see these screens they may be a bit overwhelming!

https://storage.googleapis.com/gweb-cloudblog-publish/images/Figure_2_VM_Options-page_2.max-700x700.jpg

Figure 2 - More of the VM options

There are a variety of different operating systems available as shown in the Boot disk section (Figure 3).  Once you've selected an operating system, you may also need to select the particular version of that OS.  For operating systems with a licensing fee, that fee will be included in the price of the VM.  Try some out and see how the price changes.


If you already know what your memory and CPU needs are, we have a tool that will help you pick the best options for your VM.  It takes quite a few factors into consideration beyond just those, such as how much performance fluctuations matter and your preferred type of processor.  Give it a try!


The boot disk section also gives you the ability to use custom images, snapshots, and existing VMs to create your image.  You can find out more about these in the reference section.

https://storage.googleapis.com/gweb-cloudblog-publish/images/Figure_3_VM_Options-page_3.max-900x900.jpg

Figure 3 - Some of the built-in OS options

Connecting to the VM 

Once you've set the options, select Create, which will return you to the VM instances page, as shown in Figure 4.  Once there's a checkmark next to the VM, it's ready to go.  You can access it by going to the Connect column of the instance information and click SSH.  It will then open in a new browser window.  At this point you can administer the machine, set up accounts, install software, etc. just as you'd do with any Linux machine.  You're already set up as a superuser of the machine.

https://storage.googleapis.com/gweb-cloudblog-publish/images/Figure_4_VM_instances.max-600x600.jpg

Figure 4 - The VM instances page 

Cleaning up

There is a charge to both keep a VM running and to store its boot disk.  You can stop the charge to run the VM by selecting it on the VM instances page and then clicking stop.  If you won't be using this VM again, you can select the VM and press Delete instead.


Yes, the tutorial shows you exactly how to do this!


While there are lots more details about Compute Engine, you've got the big picture now.  Go do something creative and useful with it!

So what now?

What are you ready to explore next?  There are lots of Compute Engine interactive tutorials available, but some good next steps include:

Posted in