Step 1. Set Up a Google Cloud Account.
- Sign up for Google Cloud: If you don’t already have a Google Cloud account, sign up at Google Cloud Console. You might be given free credits upon signing up.
- Log in: Once your account is set up, log in to the Google Cloud Console.
Step 2. Create a New Project.
- In the Google Cloud Console, click the project dropdown at the top-left corner.
- Click New Project.
- Name your project, select a billing account, and choose a location for your project.
- Click Create.
Step 3. Enable Compute Engine API.
- In the Google Cloud Console, open the Navigation Menu (three horizontal lines in the top-left corner).
- Navigate to Compute Engine > VM instances.
- If it's your first time using the Compute Engine, click Enable to activate the Compute Engine API.
Step 4. Create a Virtual Machine (VM) Instance with Ubuntu 22.04.
Once Compute Engine is enabled, click Create to start creating a new VM instance.
Configure the VM
- Name: Choose a name for your VM (e.g., ubuntu server).
- Region & Zone: Select the region and zone where you want your VM to be hosted. For example, you can select us-central1 for the region and us-central1-a for the zone.
- Machine Type: Choose the machine type. The default e2-medium is suitable for most basic use cases. You can always adjust this based on your needs.
- Boot Disk
- Click on Change next to the Boot Disk option.
- Select Ubuntu as the operating system and choose Ubuntu 22.04 LTS as the version.
- Set the disk size (e.g., 10 GB should be fine for basic usage).
- Firewall: Check both Allow HTTP traffic and Allow HTTPS traffic if you plan to host a web service.
Step 5. Configure Networking (Optional)
- Under the Networking section, you can configure any additional network settings. For basic use, the default settings should be sufficient.
- You can also assign a static external IP (optional) if you want to keep the same IP address even after restarting your VM.
Step 6. Create the Instance
- Once all settings are configured, click Create to launch your VM instance.
- GCP will start provisioning your VM. This may take a minute or two, and once it's ready, you'll be redirected to the VM instances page, where your newly created instance will be listed.
Step 7. Connect to Your Ubuntu 22.04 VM Instance
- Once your VM is created, go to the VM instances page in the Google Cloud Console.
- Find your newly created instance and click the SSH button next to it to connect via SSH using Google Cloud's browser-based terminal.
- If you're using a local SSH client, you can connect to the instance using the external IP address (if assigned a static IP). Run the below command in your terminal.
gcloud compute ssh [YOUR_INSTANCE_NAME] --zone [YOUR_ZONE]
Replace [YOUR_INSTANCE_NAME] and [YOUR_ZONE] with the appropriate values.
Step 8. Start Using Your Ubuntu 22.04 Instance.
Once connected to your Ubuntu 22.04 server, you’ll be able to run commands and install software as needed.
Update package lists: Run the following command to update the system.
sudo apt update
sudo apt upgrade -y
Install Software: You can install any required software by using the apt package manager. For example.
- sudo apt install nginx # Install Nginx web server
- sudo apt install python3 # Install Python 3
Step 9. Managing the Instance
- Stopping the Instance: You can stop your instance when you no longer need it. In the VM instances section, click Stop next to your instance.
- Deleting the Instance: If you no longer need the instance, click Delete next to your instance to terminate it.
Step 10. Secure Your Instance (Optional)
- SSH Keys: It’s recommended to use SSH keys for secure access instead of passwords, especially for production environments.
- Firewalls: You can configure firewall rules for more granular control over what traffic can reach your instance.
Output