DEV Community

Shahriyar Al Mustakim Mitul
Shahriyar Al Mustakim Mitul

Posted on

Create a Virtual Machine Using the command line in Google Cloud Platform

Lets first select the Region and zones:
Assume that we want to select us-central1 region:
Set this in your GCP terminal

MY_REGION=us-central1
Enter fullscreen mode Exit fullscreen mode

Image description

To check the zones we have

gcloud compute zones list | grep $MY_REGION
Enter fullscreen mode Exit fullscreen mode

Image description

Now select anyone of the zones and copy paste it for the value

MY_ZONE=<Your desired zone>
Enter fullscreen mode Exit fullscreen mode

Image description

Set this zone to be your default zone by executing the following command

gcloud config set compute/zone $MY_ZONE
Enter fullscreen mode Exit fullscreen mode

Execute the following command to store a name in an environment variable you will use to create a VM. You will call your VM second-vm

MY_VMNAME=second-vm
Enter fullscreen mode Exit fullscreen mode

Create a VM in the default zone that you set earlier in this task using the new environment variable to assign the VM name

gcloud compute instances create $MY_VMNAME \
--machine-type "e2-standard-2" \
--image-project "debian-cloud" \
--image-family "debian-11" \
--subnet "default"
Enter fullscreen mode Exit fullscreen mode

Image description

Go to Navigation bar and then Compute Engine and then VM instances.

Image description
So, you can see your vm created.

Although you can check out using this command line:

List the virtual machine instances in your project
Enter fullscreen mode Exit fullscreen mode

Image description

Done!

Top comments (1)

Collapse
 
huzaifi0604 profile image
Muhammad Huzaifa

Very Informative. 👏
I created an article a while back regarding VMs on Azure using SSH as well as RDP for GUI based VMs and hosting websites cost free on them. Do check that out as well.

huzzaifaasim.medium.com/a-beginner...