How to Install VS Code on Ubuntu
Introduction
Visual Studio Code (VSCode) is a powerful, versatile, and free source-code editor developed by Microsoft. It has gained immense popularity among developers due to its lightweight nature, extensive feature set, and robust ecosystem of extensions. VSCode supports a wide array of programming languages and frameworks, making it an ideal choice for both beginners and experienced developers alike.
For Ubuntu users, installing VSCode opens up a world of possibilities in terms of code editing, debugging, and version control integration. Whether you're a web developer, a data scientist, or a system administrator, VSCode can significantly enhance your productivity and streamline your workflow.
In this guide, we'll walk you through the process of installing Visual Studio Code on Ubuntu. We'll cover multiple installation methods, ensuring that you can choose the one that best suits your needs and comfort level with the Ubuntu operating system.
Prerequisites
Before we dive into the installation process, let's ensure you have everything you need to successfully install Visual Studio Code on your Ubuntu system. Here are the prerequisites:
-
Ubuntu Operating System:
- VSCode is compatible with Ubuntu 16.04 and later versions.
- Ensure your Ubuntu system is up to date by running
sudo apt update && sudo apt upgrade
in the terminal.
-
Internet Connection:
- A stable internet connection is required to download VSCode and its dependencies.
- If you're on a metered connection, note that the download size is approximately 60-70 MB.
-
Basic Terminal Knowledge:
- Some installation methods require using the command line.
- Familiarity with basic terminal commands will be helpful.
-
Sudo Privileges:
- You'll need sudo access to install software on your Ubuntu system.
- Ensure you know your system's sudo password.
-
Adequate Disk Space:
- VSCode requires about 200 MB of disk space.
- Ensure you have sufficient free space on your system.
-
Supported Architecture:
- VSCode supports 64-bit systems.
- To check your system architecture, run
uname -m
in the terminal. It should returnx86_64
.
Method 1: Install VSCode from Ubuntu Software Center
The Ubuntu Software Center provides a graphical interface for installing applications, making it an ideal choice for users who prefer a visual approach. Here's how to install Visual Studio Code using this method:
-
Open Ubuntu Software Center:
- Click on the Ubuntu Software icon in the dock or search for "Ubuntu Software" in the Activities overview.
-
Search for VSCode:
- Once the Software Center opens, click on the search bar at the top.
- Type "Visual Studio Code" or simply "VSCode" and press Enter.
-
Locate Visual Studio Code:
- You should see Visual Studio Code in the search results.
- It's usually listed with the official VSCode icon and published by Microsoft.
-
Install VSCode:
- Click on the Visual Studio Code entry to open its details page.
- Click the "Install" button.
- You may be prompted to enter your password to authorize the installation.
-
Wait for the Installation to Complete:
- The Software Center will download and install VSCode.
- This process usually takes a few minutes, depending on your internet speed.
-
Launch VSCode:
- Once the installation is complete, you can click the "Launch" button in the Software Center.
- Alternatively, you can find VSCode in your Applications menu or search for it in the Activities overview.
Method 2: Install VSCode using APT
Installing VSCode using APT (Advanced Package Tool) is a more robust method that ensures you get the latest version directly from Microsoft. This method involves adding Microsoft's official repository to your system. Here's how to do it:
-
Update Package Index: Open a terminal and run the following command to ensure your package index is up-to-date:
sudo apt update
-
Install Dependencies: Install necessary dependencies by running:
sudo apt install software-properties-common apt-transport-https wget
-
Import Microsoft GPG Key: Import the Microsoft GPG key to ensure the integrity of the packages:
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
-
Add VSCode Repository: Enable the VSCode repository:
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
-
Update Package Index Again: After adding the new repository, update the package index:
sudo apt update
-
Install VSCode: Finally, install Visual Studio Code:
sudo apt install code
-
Verify Installation: Once the installation is complete, you can verify it by checking the version:
code --version
This method offers several advantages:
- You'll always have access to the latest version of VSCode.
- Updates will be managed through Ubuntu's standard update process.
- It's easier to automate in scripts for system setup.
Method 3: Install VSCode using .deb package
Installing VSCode using a .deb package is another straightforward method. This approach is useful if you want to download the package first and install it later, or if you need to install VSCode on a machine without internet access. Here's how to do it:
-
Download the .deb Package:
- Open a web browser and go to the official Visual Studio Code website: https://code.visualstudio.com/
- Click on the download button for Linux.
- Select the .deb package for Ubuntu/Debian.
- The download should start automatically.
-
Locate the Downloaded File:
- By default, the file should be in your Downloads folder.
- The filename will look something like
code_1.XX.X-XXXXXXXXXX_amd64.deb
, where X represents version numbers.
-
Install Using GUI (Option 1):
- Once the download is complete, double-click on the .deb file.
- This should open the Ubuntu Software Center.
- Click on the "Install" button.
- Enter your password when prompted to authorize the installation.
-
Install Using Terminal (Option 2):
- If you prefer using the terminal, you can install the .deb package using the following command:
sudo dpkg -i ~/Downloads/code_1.XX.X-XXXXXXXXXX_amd64.deb
- Replace the X's with the actual version number of your downloaded file.
- If you encounter any dependency issues, run:
sudo apt install -f
- If you prefer using the terminal, you can install the .deb package using the following command:
-
Verify the Installation:
- After installation, you can verify it by opening VSCode from the Applications menu or by running
code
in the terminal.
- After installation, you can verify it by opening VSCode from the Applications menu or by running
This method has some advantages:
- It allows for offline installation if you download the .deb file on another machine.
- You have control over which version you install.
- It's useful for mass deployment in organizations.
Post-Installation Steps
After successfully installing Visual Studio Code on your Ubuntu system, there are a few steps you might want to take to ensure the best experience:
-
Launching VSCode:
- You can launch VSCode in several ways:
- Click on the VSCode icon in your Applications menu
- Search for "Visual Studio Code" in the Activities overview
- Use the terminal by typing
code
and pressing Enter
- You can launch VSCode in several ways:
-
Setting Up Command Line Integration:
- VSCode can be launched from the terminal to open files or folders.
- To enable this, open VSCode and:
- Press
Ctrl+Shift+P
to open the Command Palette - Type "shell command" and select "Shell Command: Install 'code' command in PATH"
- Press
- After this, you can use commands like
code .
to open the current directory in VSCode
-
Installing Extensions:
- VSCode's functionality can be extended with extensions.
- To install extensions:
- Click on the Extensions icon in the left sidebar (or press
Ctrl+Shift+X
) - Search for extensions you need (e.g., Python, C++, JavaScript)
- Click "Install" on the extensions you want
- Click on the Extensions icon in the left sidebar (or press
-
Configuring Settings:
- Customize VSCode to your liking:
- Go to File > Preferences > Settings (or press
Ctrl+,
) - Here you can adjust various settings like theme, font size, indentation, etc.
- Go to File > Preferences > Settings (or press
- Customize VSCode to your liking:
-
Updating VSCode:
- If you installed via APT or Software Center:
- VSCode will update automatically with your system updates
- You can manually check for updates by running:
sudo apt update sudo apt upgrade
- If you installed via .deb package:
- You'll need to download and install new versions manually
- VSCode will notify you when updates are available
- If you installed via APT or Software Center:
-
Learning Keyboard Shortcuts:
- VSCode has many useful keyboard shortcuts
- View all shortcuts by going to File > Preferences > Keyboard Shortcuts
- Some popular shortcuts:
Ctrl+P
: Quick file openingCtrl+Shift+P
: Command PaletteCtrl+/
: Toggle line comment
Frequently Asked Questions (FAQ)
Q: Is Visual Studio Code free to use?
A: Yes, Visual Studio Code is free and open-source software. It's available for use without any charge.
Q: Can I use VSCode for languages other than those made by Microsoft?
A: Absolutely! VSCode supports a wide range of programming languages through its extensible system. You can find extensions for languages like Python, Java, C++, Ruby, and many more.
Q: How do I uninstall VSCode if I no longer need it?
A: To uninstall VSCode, you can use the following command in the terminal:
sudo apt remove code
If you installed it via .deb package, you might need to use:
sudo dpkg -r code
Q: VSCode isn't recognizing my programming language. What should I do?
A: You may need to install the appropriate language extension. Open VSCode, go to the Extensions view (Ctrl+Shift+X), and search for your language to find and install the relevant extension.
Q: Can I sync my VSCode settings across multiple computers?
A: Yes, VSCode offers a Settings Sync feature. You can turn it on by clicking on the gear icon in the lower-left corner and selecting "Turn on Settings Sync."
Q: How often is VSCode updated?
A: Microsoft typically releases updates for VSCode on a monthly basis. These updates include bug fixes, performance improvements, and new features.
Q: Can I use VSCode for remote development?
A: Yes, VSCode supports remote development through its Remote Development extension pack. This allows you to use a container, remote machine, or Windows Subsystem for Linux (WSL) as a full-featured development environment.
Q: Is VSCode the same as Visual Studio?
A: No, VSCode (Visual Studio Code) is different from Visual Studio. VSCode is a lightweight, cross-platform code editor, while Visual Studio is a full-fledged Integrated Development Environment (IDE) primarily for Windows.
Q: Can I contribute to VSCode's development?
A: Yes, VSCode is open-source, and Microsoft welcomes contributions. You can find the source code and contribution guidelines on their GitHub repository.
Q: My system tray icon for VSCode is missing. How can I fix this?
A: This is a known issue on some Linux distributions. You can try installing the libappindicator1
package:
sudo apt install libappindicator1
If that doesn't work, you might need to use a GNOME shell extension like "TopIcons Plus" to display the icon.