Visual Studio Code, better known as VSCode, is a powerful code editor developed by Microsoft and 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 broad 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 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 that are 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.
Method 1: Install VSCode 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
Finalize VSCode Installation via APT Commands
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 suits those comfortable with experimental features and wishing to contribute feedback.
Method 2: Install VSCode 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 VSCode 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.
Method 3: Install VSCode via Flatpak and Flathub
Enable the Flathub Repository for VSCode
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.
Proceed to Install VScode via Flatpak Command
With Flathub enabled, installing Visual Studio Code is your next step. Flatpak simplifies this process, allowing you to install the application directly from the Flathub repository.
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
CLI Method to Launch VSCode
After installing Visual Studio Code on Ubuntu, you can start it using various methods. The command line is convenient if you’re comfortable with the terminal or need to open VSCode in a specific directory.
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
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
For users preferring a graphical interface, Ubuntu’s GUI simplifies launching Visual Studio Code.
Follow these steps:
- 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.
- Then, select Show Applications, represented by a grid or ‘nine dots’ icon at the bottom of the dock on the left.
- In the search bar, type “Visual Studio Code.” The VSCode icon appears as you type.
- Click on the icon to launch Visual Studio Code.
Managing Visual Studio Code
Remove VSCode
APT Method To Remove VSCode
The approach to uninstalling Visual Studio Code installed via APT depends on your version. 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, removing the associated repository is important 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 removes Visual Studio Code from your Ubuntu system, leaving no residual files.
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 are a coding enthusiast or a professional developer, Visual Studio Code is 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!
Useful Links
Here are some valuable links related to using Visual Studio Code (VSCode):
- VSCode Official Website: Visit the official Visual Studio Code website to download the editor, learn about its features, and stay updated with the latest releases.
- VSCode Documentation: Access comprehensive documentation to guide you through installation, configuration, and advanced usage of VSCode.
- VSCode Learning Resources: Explore tutorials, videos, and articles to help you get the most out of Visual Studio Code.
- VSCode GitHub Repository: Visit the official GitHub repository to access the source code, report issues, contribute to development, and view the latest updates.