This content originally appeared on DEV Community and was authored by Godfrey Nyarko
Have you ever thought about using VS Code while accessing your virtual machine? This blog covers how to do that. By connecting your virtual machine with VS Code, you can leverage the features of both.
Prerequisites:
You should have some knowledge of VS Code and virtual machines. The following are needed:
- VS Code
- Git
- VirtualBox
- Virtual machine
- Vagrant
In this guide, an Ubuntu virtual machine is used. To set up your Ubuntu virtual machine, click here.
Getting Started:
Starting up the Virtual Machine:
- Launch your Git application.
- Type
vagrant up
to start the virtual machine. - Type
vagrant global-status
to check if the virtual machine is running. - Type
vagrant ssh-config
to get the configuration of the virtual box for setting up remote access in VS Code. Copy and save this configuration to your notepad.
Installing the Remote-SSH Extension in VS Code:
- Open VS Code and click on the
Extensions tab
. - Search for
Remote SSH
in the extension search box and click Install.
Connecting to the Virtual Machine:
- Click on the
Remote SSH tab
. - Click on the
+
sign in the SSH options panel. - Enter a name of your choice in the new search box and press Enter.
- Select
C:\Users\<your-username>\.ssh\config
and press Enter. - Select
Open Config
from the pop-up message in the lower right-hand corner. - Copy and paste the configuration from your notepad into the new panel. (Remember to delete anything in the opened config file before pasting the configuration)
- Optionally, change the Hostname from the
default
to your preferred name. - Close the panel containing the Host details.
- Click
Refresh
on the control panel of Remote SSH. - Click on
>
to find your new SSH platform. - Select and click on the arrow sign on your new SSH platform to connect.
- Select
Linux
from the pop-up search bar (since Ubuntu is a Linux distribution). - Wait for the connection to be established.
- After connecting, click on the three dots in the upper bar of VS Code and select
Terminal
. - Click on
New Terminal
to open the terminal in VS Code.
You will notice that your VS Code terminal can now access your virtual machine terminal. Remember to always vagrant up
your virtual machine using Git before opening VS Code after a shutdown or restart of your laptop or PC.
This content originally appeared on DEV Community and was authored by Godfrey Nyarko
Godfrey Nyarko | Sciencx (2024-06-27T06:31:55+00:00) Connect a VM with VS Code for Remote Development. Retrieved from https://www.scien.cx/2024/06/27/connect-a-vm-with-vs-code-for-remote-development/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.