How to Install Visual Studio Code on Ubuntu 24.04, 22.04 or 20.04

This guide will cover how to install Visual Studio Code on Ubuntu 24.04, 22.04, or 20.04 LTS releases using the command-line terminal, with three different methods: APT with Microsoft’s official APT repository, Snapcraft, or Flatpak with Flathub.

Visual Studio Code, a powerful code editor developed by Microsoft, has become increasingly popular among developers for its versatility and robust feature set. This lightweight but feature-rich editor is designed to streamline the coding process, offering a range of functionalities that cater to a wide spectrum of programming needs. Some of its standout features include:

  • Intelligent Code Completion: Offers context-aware code suggestions, speeding up the coding process.
  • Debugging Tools: Integrated debugging tools for a seamless troubleshooting experience.
  • Extension Marketplace: Access to a vast collection of extensions to customize and enhance functionality.
  • Git Integration: Simplifies version control with built-in Git commands.
  • Customizable Workspace: Personalize the layout with themes, keyboard shortcuts, and preferences.
  • Multi-Language Support: Accommodates a wide range of programming languages out-of-the-box.

With these key features and highlights covered, let’s delve into the main article and explore the various methods to install Visual Studio Code on your Ubuntu system.

Install Visual Studio Code on Ubuntu via Microsoft APT Repository

Update Ubuntu Packages Before Installing VSCode

Start by updating your Ubuntu system’s packages. This step is essential to avoid conflicts during the Visual Studio Code installation due to outdated packages.

Run the command in your terminal:

sudo apt update

This command synchronizes your system with Ubuntu’s repositories to get the latest updates for your installed packages.

Next, upgrade any outdated packages to prepare your system for the Visual Studio Code installation:

sudo apt upgrade

Install Initial Packages for VSCode

After updating your system, install necessary packages that facilitate the installation of Visual Studio Code. These include dirmngr, software-properties-common, apt-transport-https, and curl. Each of these plays a role in managing repositories, secure data transfer, and handling HTTPS transport.

Execute the following command to install these packages:

sudo apt install dirmngr software-properties-common apt-transport-https curl -y

Import Microsoft’s Visual Studio Code Repository

Now, import Microsoft’s GPG key to verify the authenticity of the Visual Studio Code package. This step ensures the software’s integrity.

Import the GPG key with this command:

curl -fSsL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor | sudo tee /usr/share/keyrings/vscode.gpg > /dev/null

Then, add the Microsoft Visual Studio Code Source Repository, which contains the Visual Studio Code packages:

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 (VSCode) via APT Command

Refresh the apt package manager’s sources list to recognize the newly added Visual Studio Code repository:

sudo apt update

To install the stable build of Visual Studio Code, which is the official and thoroughly tested version, use:

sudo apt install code

If you prefer the insider’s build, which offers early access to new features but may be less stable, install it with:

sudo apt install code-insiders

The insider build is suitable for those who are comfortable with experimental features and wish to contribute feedback.

Install Visual Studio Code on Ubuntu via Snapcraft

Ensure Snap is Installed

First, confirm that Snap, Ubuntu’s default package manager, is installed on your system. Snap is vital for installing applications in isolated environments, enhancing stability and security. If Snap is not already installed, or if you’re using an Ubuntu version that doesn’t include it, you will need to install it.

Install or verify Snap using this command:

sudo apt install snapd

This command sets up the snapd service, which allows you to run Snap applications on Ubuntu.

Install Visual Studio Code via Snap Command

Once snapd is operational, installing Visual Studio Code is a simple task. Just execute this command:

sudo snap install code --classic

For developers eager to experiment with the latest features, Snap offers an insider build of Visual Studio Code. This version can be installed alongside the stable release:

sudo snap install code-insiders --classic

The --classic flag in these commands is essential. It gives Visual Studio Code full system access, akin to traditional packages. This access is necessary for Visual Studio Code to function without limitations, ensuring users have access to all its features and capabilities.

Install Visual Studio Code on Ubuntu via Flatpak and Flathub

Enable the Flathub Repository for Visual Studio Code

Begin by integrating the Flathub repository into your system. Flathub is a central repository for Flatpak applications and offers a wide range of software, including Visual Studio Code. Enabling Flathub ensures access to the latest versions of these applications.

Run this command to add Flathub to your Flatpak configuration:

sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

The --if-not-exists flag is crucial here, preventing errors if Flathub is already configured on your system.

Install Visual Studio Code via Flatpak Command

With Flathub enabled, installing Visual Studio Code is your next step. Flatpak simplifies this process, allowing you to install the application from the Flathub repository directly.

Execute this command to start the installation:

flatpak install flathub com.visualstudio.code

This command fetches and installs Visual Studio Code from Flathub. Once the installation is completed, Visual Studio Code will be set up and ready for use on your Ubuntu system.

Launching Visual Studio Code on Ubuntu

CLI Method to Launch VSCode on Ubuntu

After installing Visual Studio Code on Ubuntu, you can start it using various methods. If you’re comfortable with the terminal or need to open VSCode in a specific directory, the command line is a convenient option.

For those who installed the stable version of Visual Studio Code, open it via the terminal with the following:

code

If you’re using the insider build, which offers early access to new features, launch it with:

code-insiders

For Flatpak installations, use this command:

flatpak run com.visualstudio.code

And for Snap installations, the command is:

snap run code

For Snap installations of the VSCode insider build, use:

snap run code-insiders

GUI Method to Launch VSCode on Ubuntu

For users preferring a graphical interface, Ubuntu’s GUI simplifies the process of launching Visual Studio Code.

Follow these steps:

  1. Click on Activities at the top left corner of the screen. This opens a dashboard with commonly used applications and an overview of your workspaces.
  2. Then, select Show Applications, represented by a grid or ‘nine dots’ icon at the bottom of the dock on the left.
  3. In the search bar, type “Visual Studio Code.” The VSCode icon appears as you type.
  4. Click on the icon to launch Visual Studio Code.
Launching Visual Studio Code using the application icon on Ubuntu 24.04, 22.04, 20.04
Demonstrating how to open Visual Studio Code from the Ubuntu application menu

First-Time Tips for Visual Studio Code on Ubuntu Linux

Now that you have successfully installed Visual Studio Code on Ubuntu, here are some first-time tips to help you get started with the software effectively:

General Tips

  • Explore the Command Palette: Use Ctrl+Shift+P to access the Command Palette. It’s a powerful feature for running commands and accessing various parts of the editor.
  • Understanding Workspaces: Workspaces in VS Code are collections of your project files and settings. Learn to manage them efficiently to improve your workflow.
  • Keyboard Shortcut Customization: Customize keyboard shortcuts to suit your workflow. Access this through File > Preferences > Keyboard Shortcuts.
  • Integrated Terminal Usage: Access the integrated terminal using Ctrl+`. It’s a convenient way to execute shell commands without leaving the editor.

Customizations

  • Theme Selection: Personalize your editor by selecting a theme. Go to File > Preferences > Color Theme to explore the available options.
  • Font Adjustments: Enhance readability by adjusting the font size and family. This can be done in File > Preferences > Settings.
  • Install Extensions: Enhance functionality by exploring extensions. Press Ctrl+X or go to the Extensions view by clicking on the square icon on the sidebar.
  • Customize the Sidebar: Organize your sidebar to suit your needs. You can reorder, hide, or add new sections for better accessibility.

Other Tips

  • Use the Zen Mode: For distraction-free coding, try Zen Mode by pressing Ctrl+K Z. It hides all the UI elements except the editor.
  • Learn About Snippets: Snippets are templates that make it easier to enter repeating code patterns. Customize or create your snippets for faster coding.
  • Explore Code Folding: Use code folding to hide sections of your code for better readability. This can be done by clicking the arrow next to the line numbers.
Screenshot showcasing the first-time launch of Visual Studio Code on Ubuntu 22.04 or 20.04, indicating a successful installation.
A glimpse of what users can expect when launching Visual Studio Code for the first time on Ubuntu 22.04 or 20.04 after a successful installation.

Managing Visual Studio Code on Ubuntu

Remove VSCode

APT Method To Remove VSCode

To uninstall Visual Studio Code installed via APT, the approach depends on the version you have. For the stable build of Visual Studio Code, execute this command:

sudo apt remove code

If you installed the insider’s build, use:

sudo apt remove code-insiders

Confirm the uninstallation by typing y and pressing Enter. This removes Visual Studio Code from your system.

After uninstalling, it’s important to remove the associated repository to stop future update checks for the uninstalled software. Run:

sudo rm /etc/apt/sources.list.d/vscode.list

Finally, delete the GPG key associated with Visual Studio Code for security purposes:

sudo rm /usr/share/keyrings/vscode.gpg

Flatpak Method To Remove VSCode

If you installed Visual Studio Code using Flatpak, the uninstallation process is simple. Use this command:

flatpak uninstall com.visualstudio.code

Snap Method To Remove VSCode

For removal of Visual Studio Code installed via Snap, execute:

sudo snap remove code

And for the insider build installed via Snap:

sudo rm code-insiders

Each method completely removes Visual Studio Code from your Ubuntu system, leaving no residual files behind.

Closing Thoughts

We’ve navigated through the comprehensive steps of installing, launching, and managing Visual Studio Code on Ubuntu, exploring various methods like APT, Snap, and Flatpak. Whether you’re a coding enthusiast or a professional developer, Visual Studio Code stands out as a versatile and powerful tool for your development needs. Remember, keeping your installation updated and understanding how to manage it effectively can significantly enhance your coding experience. As you delve into your projects, make the most of this robust editor and tailor it to fit your workflow. Happy coding!

Leave a Comment