Install Visual Studio Code on Ubuntu 22.04: Best VS Code Setup
This tutorial is designed to guide you through the process of Install Visual Studio Code on Ubuntu 22.04. Visual Studio Code (VS Code) is a highly popular, free, and lightweight source code editor that is available across multiple platforms including Windows, macOS, Linux, and Raspberry Pi OS, both as a desktop application and a web-based editor.
It boasts native support for JavaScript, TypeScript, and Node.js, further enhanced by a vast ecosystem of extensions that cater to various programming languages like C++, C#, Java, Python, PHP, and Go; runtimes such as .NET and Unity; environments like Docker and Kubernetes; and cloud platforms including Amazon Web Services, Microsoft Azure, and Google Cloud Platform.
Now, let’s follow the steps outlined below to complete the Install Visual Studio Code on Ubuntu 22.04 setup.
To proceed with this guide, ensure you are logged into your Ubuntu 22.04 server as a non-root user with sudo privileges. If you haven’t already set this up, you can refer to a guide on Initial Server Setup with Ubuntu 22.04.
Step 1. Install VS Code on Ubuntu 22.04
First, update your local package index to ensure you have the latest information about available packages:
sudo apt update
Next, install the necessary dependencies to manage software repositories and handle HTTPS connections:
sudo apt install software-properties-common apt-transport-https -y
Import Microsoft GPG Key
To ensure the authenticity of the packages you’ll be installing from the Microsoft repository, import the Microsoft GPG key using the wget
command:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor | sudo tee /usr/share/keyrings/vscode.gpg
Add VS Code Repository
Now, add the VS Code repository to your Ubuntu 22.04 system’s list of software sources:
echo deb [arch=amd64 signed-by=/usr/share/keyrings/vscode.gpg] https://packages.microsoft.com/repos/vscode stable main | sudo tee /etc/apt/sources.list.d/vscode.list
Install Visual Studio Code
Finally, you can now proceed with the installation of Visual Studio Code on Ubuntu 22.04:
# sudo apt update
# sudo apt install code
Step 2. Launch VS Code on Ubuntu 22.04
You can launch VS Code from the command line by simply typing code
:
code
Alternatively, you can launch it through the graphical interface by navigating to "Applications -> Programming -> Visual Studio Code."
Upon the first launch of VS Code, you’ll be greeted with an introductory window, ready for customization.
You can now start installing extensions and tailoring VS Code to suit your specific development needs.
Step 3. Update VS Code on Ubuntu 22.04
When a new version of Visual Studio Code becomes available, you can update the package using the standard Software Update tool within your desktop environment. Alternatively, you can update it via the command line:
# sudo apt update
# sudo apt upgrade
Conclusion
Visual Studio Code (VS Code) is a versatile and powerful code editor that empowers developers to efficiently write, edit, and debug code. By following this guide, you’ve successfully learned how to Install Visual Studio Code on Ubuntu 22.04.
FAQs
Can I install VS Code using Snap?
Yes, VS Code is available as a Snap package. You must install Snap and then use the command below to get the VS code:sudo snap install code --classic
How to uninstall VS Code on Ubuntu?
You can remove Visual Studio with the following command:sudo apt remove code
Also, it is better to remove its repository with the command below:sudo rm /etc/apt/sources.list.d/vscode.list
Then, run the autoclean command on your system:sudo apt autoclean
Alternative Installation Methods for VS Code on Ubuntu 22.04
While the article details the recommended method of installing Visual Studio Code on Ubuntu 22.04 using the official Microsoft repository, there are alternative approaches you can take. Here are two such methods: using the Snap Store and downloading and installing the .deb package directly.
1. Installing VS Code via the Snap Store
Snap is a package management system developed by Canonical, the company behind Ubuntu. It allows for easy installation and automatic updates of applications. VS Code is available as a Snap package, providing a convenient alternative to the APT method.
Explanation:
Snaps are containerized software packages that include all their dependencies, ensuring they run consistently across different Linux distributions. This eliminates potential dependency conflicts and simplifies the installation process. The Snap Store also handles automatic updates, keeping your VS Code installation current without requiring manual intervention.
Installation Steps:
-
Ensure Snap is Installed: Ubuntu 22.04 comes with Snap pre-installed. You can verify this by running
snap version
in your terminal. If it’s not installed, you can install it using:sudo apt update sudo apt install snapd
-
Install VS Code: Use the following command to install VS Code from the Snap Store:
sudo snap install code --classic
The
--classic
flag is necessary because VS Code requires access to system resources beyond the default Snap confinement. -
Launch VS Code: Once the installation is complete, you can launch VS Code from the command line using
code
or through the applications menu.
Example:
# Output of snap version (example)
snap 2.57.5
snapd 2.57.5
series 16
ubuntu 22.04
kernel 5.15.0-56-generic
# Installation command
sudo snap install code --classic
2. Installing VS Code via .deb Package Download
Another method involves downloading the .deb package directly from the Visual Studio Code website and installing it using dpkg
, the Debian package manager.
Explanation:
This method provides more control over the installation process, as you can choose the specific version of VS Code you want to install. However, it also requires you to manually manage updates, unlike the APT and Snap methods, which handle updates automatically.
Installation Steps:
-
Download the .deb Package: Visit the official Visual Studio Code download page (https://code.visualstudio.com/download) and download the .deb package for Ubuntu.
-
Navigate to the Download Directory: Open your terminal and navigate to the directory where you downloaded the .deb package (usually the
Downloads
directory).cd Downloads
-
Install VS Code: Use the
dpkg
command to install the package:sudo dpkg -i <package_name>.deb
Replace
<package_name>.deb
with the actual name of the downloaded file (e.g.,code_1.74.0-1671093168_amd64.deb
). -
Fix Dependency Issues (if any): If you encounter any dependency issues during the installation, run the following command to resolve them:
sudo apt-get install -f
-
Launch VS Code: Once the installation is complete, you can launch VS Code from the command line using
code
or through the applications menu.
Example:
# Example .deb package name
code_1.74.0-1671093168_amd64.deb
# Installation command
sudo dpkg -i code_1.74.0-1671093168_amd64.deb
# Output if dependencies are missing (example)
dpkg: dependency problems prevent configuration of code:
code depends on libxkbfile1; however:
Package libxkbfile1 is not installed.
# Fix dependencies
sudo apt-get install -f
These alternative methods offer flexibility in how you choose to Install Visual Studio Code on Ubuntu 22.04, allowing you to select the approach that best suits your preferences and system configuration. While the APT method is generally recommended for its ease of use and automatic updates, the Snap and .deb package methods provide viable alternatives for specific scenarios. Regardless of the method you choose, you’ll have access to the powerful features of VS Code for your development projects.