How To Install VS Code on Ubuntu: Step-by-Step Guide for Developers

Visual Studio Code (VS Code) is a popular, lightweight code editor packed with features to streamline your development process. If you’re using Ubuntu, installing VS Code is straightforward and takes just a few steps. Whether you’re a beginner or an experienced developer, setting it up ensures you have a powerful tool at your fingertips.

To get started, you’ll first update your system to ensure compatibility. Next, you’ll add the Microsoft GPG key and repository to access the latest VS Code version. Finally, you’ll install the editor using a simple command. By the end, you’ll have VS Code ready to customize and use for your projects.

Overview Of Visual Studio Code

Visual Studio Code (VS Code) is a source code editor developed by Microsoft. It’s designed to support multiple programming languages, offering features such as debugging, syntax highlighting, version control, and flexible extensions. As an open-source tool, VS Code is widely adopted by developers due to its performance, lightweight design, and extensive ecosystem.

You can customize the interface, integrate third-party tools, and utilize built-in features like IntelliSense for smart code completion. It supports Linux, macOS, and Windows, making it versatile across operating systems. With compatibility for various file formats and continuous updates, VS Code streamlines development workflows.

Its marketplace offers thousands of extensions, including language support (e.g., Python, JavaScript) and tools for Docker, GitHub, and more. This flexibility enhances productivity for coding, debugging, and project management.

System Requirements For Ubuntu

To successfully install and run VS Code on Ubuntu, your system must meet certain requirements. These prerequisites ensure optimal performance and compatibility.

Supported Ubuntu Versions

  • Ubuntu 20.04 LTS or newer
  • Non-LTS versions may not guarantee consistent support

Hardware Requirements

  • Processor: 2 GHz or faster, 64-bit architecture
  • Memory (RAM): Minimum 2 GB; 4 GB recommended for enhanced performance
  • Disk Space: At least 200 MB of free storage for installation files
  • Display: 1024 x 768 resolution or higher

Software Dependencies

  • glibc version: 2.28 or newer
  • GTK version: 3.20 or later
  • libX11: Required for graphical interface rendering

Internet Connection

Access to a stable connection is necessary for downloading the installation files and updating extensions.

Verify these requirements before proceeding to avoid errors during installation.

Methods To Install VS Code On Ubuntu

You can install Visual Studio Code on Ubuntu using different methods, depending on your preferences. Below are the step-by-step instructions for three common methods.

Using The Snap Package

The Snap package offers a straightforward way to install VS Code.

  1. Enable Snap Support: Confirm that Snap is installed by running snap --version. If it’s unavailable, install Snap by executing sudo apt update && sudo apt install snapd.
  2. Install VS Code: Use the command sudo snap install --classic code to install the latest stable version of VS Code.
  3. Verify Installation: After the installation completes, check the version with code --version to confirm it’s properly installed.

Snap automatically updates VS Code in the background.

Installing Via .deb File

Downloading the .deb file is another method for installing VS Code on Ubuntu.

  1. Download the Package: Go to the official VS Code website and click the .deb package download link.
  2. Open the Terminal: Navigate to the download directory using cd ~/Downloads.
  3. Install the Package: Run sudo dpkg -i <filename>.deb to install the .deb file (replace ` with the actual file name).
  4. Resolve Dependencies: If dependencies are missing, fix them by executing sudo apt --fix-broken install.

Follow these steps to successfully install and launch VS Code.

Through Command Line With Apt

Using the apt package manager ensures a comprehensive repository-based installation.

  1. Update Your System: Begin by updating your system’s repositories with sudo apt update.
  2. Add Microsoft GPG Key: Download and add the Microsoft GPG key with:

wget -qO- https://packages.microsoft.com/keys/microsoft.asc 

|


 gpg --dearmor > packages.microsoft.gpg


sudo install -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/
  1. Enable the VS Code Repository: Run:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" 

|


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

  1. Install VS Code: Finally, execute sudo apt update && sudo apt install code.

This approach provides consistent updates through apt.

Troubleshooting Common Installation Issues

Error: “Code Command Not Found”

You can encounter this error when trying to run VS Code from the terminal. Ensure VS Code is added to the system PATH. Open VS Code, press Ctrl+Shift+P, type “Shell Command”, then select Install ‘code’ command in PATH. Restart the terminal to apply changes.

Dependency Errors During Installation

If installation errors mention missing dependencies, check your system’s software requirements. Use sudo apt install -f to fix broken dependencies and ensure packages like libX11, libxkbfile1, and others are installed. View the complete dependency list in the official VS Code documentation.

Permission Denied Errors

If you see “permission denied” during installation or updates, verify you used administrative privileges. Run commands with sudo, such as sudo apt install code, to prevent access issues.

Snap Package Installation Fails

Snap issues can arise from a misconfigured Snapd service. Restart it using sudo systemctl restart snapd and ensure Snap is enabled on your system by running sudo apt install snapd. If the problem persists, clear Snap’s cache with sudo rm -rf /var/cache/snapd.

Black or Blank Screen When Launching VS Code

This occurs due to GPU-related issues. Start VS Code with the --disable-gpu flag by running code --disable-gpu in the terminal. Update graphics drivers or disable GPU acceleration permanently by modifying VS Code’s settings.json file.

Inconsistent Extension Behavior

Extensions may fail to work correctly if they’re incompatible or outdated. Open the Extensions view (Ctrl+Shift+X), check for updates, and disable incompatible extensions. Reinstall problematic extensions as a last resort.

Outdated System Packages

If system packages are outdated, the installation might not complete. Update your system using sudo apt update && sudo apt upgrade. After updating, retry the VS Code installation.

Repository-GPG Key Issues

When errors mention the GPG key, re-add it using:

`wget -qO- https://packages.microsoft.com/keys/microsoft.asc

|

sudo apt-key add –. Afterwards, update the APT repository using sudo apt update`.

Debugging Logs for Additional Help

You can gather debugging logs by starting VS Code with the --verbose flag. This reveals detailed information for diagnosing issues. Run code --verbose in the terminal to analyze execution errors and seek community help if needed.

Resolve these issues step-by-step to ensure a stable VS Code setup.

Tips For Optimizing VS Code On Ubuntu

Install Essential Extensions

Incorporate extensions to tailor VS Code to your workflow. Use extensions like Python, Prettier – Code Formatter, and GitLens for language support, syntax formatting, and version control. Search for extensions directly in the Extensions Marketplace within VS Code. These tools enhance features like debugging and code readability.

Enable Auto-Save

Reduce the risk of losing work by enabling the Auto Save feature. Go to File > Auto Save and select options like “onFocusChange” or “afterDelay” based on your preferences. This automates saving and keeps your files updated.

Adjust Performance Settings

Improve performance by tweaking VS Code settings. Disable unused extensions by navigating to Extensions > Installed and selecting Disable for non-essential tools. You can also increase speed by turning off telemetry, which sends usage data, under File > Preferences > Settings > Telemetry.

Configure Keybindings

Streamline workflow customization by modifying keybindings. Open File > Preferences > Keyboard Shortcuts to assign custom shortcuts for frequently used commands like formatting code or toggling the terminal. This saves time during coding.

Use The Integrated Terminal

Access terminals directly within VS Code to avoid switching between windows. Open the terminal via View > Terminal and configure settings like default shell and font size under Settings > Features > Terminal.

Activate Code Minimap

Enable the Minimap for quick navigation of code files. Go to View > Appearance > Show Minimap to visualize file structure alongside your editor window. It assists when scrolling through large files.

Optimize Editor Layout

Customize the editor layout for better multitasking. Open View > Editor Layout to split windows vertically or horizontally. Use drag-and-drop to adjust tab positions within split panes.

Configure Git Integration

Simplify version control by connecting VS Code to Git. Open Source Control View, initialize a repository, and link your project. Use the terminal to authenticate Git commands for committing changes and pushing to remote repositories.

Update Regularly

Keep VS Code and extensions updated for access to the latest features and security fixes. Navigate to Help > Check for Updates and update outdated extensions from the Extensions Marketplace.

Leverage Settings Sync

Synchronize settings, extensions, and keybindings across devices. Enable Settings Sync under File > Preferences > Settings Sync, then sign in with a Microsoft or GitHub account. It’s especially helpful for multi-device development.

Conclusion

Installing VS Code on Ubuntu is a straightforward process that unlocks a powerful and versatile tool for your development needs. Whether you’re writing code, debugging, or managing projects, VS Code offers an intuitive interface and extensive features to boost your productivity.

By ensuring your system meets the requirements and following the installation methods, you’ll have a reliable setup tailored to your workflow. Optimize your experience with extensions, performance tweaks, and customization options to make the most of this lightweight yet robust editor.

With VS Code at your disposal, you’re well-equipped to tackle any coding challenge efficiently on Ubuntu.

Frequently Asked Questions

What is Visual Studio Code (VS Code)?

Visual Studio Code (VS Code) is a free, lightweight, and open-source code editor developed by Microsoft. It supports multiple programming languages and includes features like debugging, syntax highlighting, IntelliSense, and integration with Git. It is highly customizable with extensions and is compatible with Linux, macOS, and Windows.

Can I install VS Code on Ubuntu?

Yes, you can install VS Code on Ubuntu. The article explains three methods: using the Snap package, downloading a .deb file, or using the apt package manager. Each method includes step-by-step instructions to guide you through the installation process.

What are the minimum system requirements to run VS Code on Ubuntu?

To run VS Code on Ubuntu, you need Ubuntu 20.04 LTS or newer, a 2 GHz or faster processor, at least 2 GB of RAM (4 GB recommended), and 200 MB of free disk space. Additionally, software dependencies include glibc 2.28 or later, GTK 3.20 or newer, and libX11.

How do I install VS Code using the Snap package on Ubuntu?

To install VS Code using Snap, ensure Snap support is enabled. Then, execute the command sudo snap install --classic code in the terminal. This method automatically downloads and installs VS Code with all dependencies.

Why is adding the Microsoft GPG key necessary for installing VS Code?

The Microsoft GPG key ensures that the installation files are trustworthy and have not been tampered with. It verifies the authenticity of the apt repository when installing VS Code using the command line.

What should I do if I see “Code Command Not Found” after installing VS Code?

This error usually means the system PATH does not include VS Code’s directory. Add the correct VS Code path to your environment variables or reinstall using Snap or apt for proper configuration.

How can I fix dependency errors during VS Code installation on Ubuntu?

Dependency errors can be fixed by running sudo apt --fix-broken install in the terminal. It resolves issues with missing or broken dependencies required for the installation.

What extensions should I install in VS Code to enhance my workflow?

Some essential VS Code extensions include Python for Python development, Prettier for code formatting, and GitLens for advanced Git integration. Customize extensions based on your programming needs for improved productivity.

How can I optimize VS Code’s performance on Ubuntu?

Disable unused extensions, turn off telemetry, and adjust performance settings to optimize VS Code. Activate features like Auto Save and configure Git for seamless version control. Keep the editor and extensions updated for the best performance.

Is there a way to sync VS Code settings across multiple devices?

Yes, use the built-in Settings Sync feature in VS Code. It allows you to synchronize your settings, extensions, and keybindings across devices by connecting VS Code to a GitHub or Microsoft account.

What should I do if VS Code shows a black screen on launch?

A black screen often indicates a graphics rendering issue. Launch VS Code with the --disable-gpu flag by running code --disable-gpu in the terminal. Update your drivers and system for a permanent solution.

How can I update VS Code and its extensions on Ubuntu?

To update VS Code, run sudo apt update && sudo apt upgrade in the terminal if installed via the apt package manager. For Snap, run sudo snap refresh. Update extensions directly in VS Code through the Extensions view.

Is Git integration available in VS Code?

Yes, VS Code includes built-in Git integration. You can initialize repositories, manage branches, stage/unstage changes, and commit directly from the editor. For enhanced functionality, install GitLens or similar extensions.

What are common reasons for VS Code installation failures on Ubuntu?

Common issues include missing dependencies, permission errors, outdated system packages, or unresponsive Snap services. Ensure your system meets the requirements, update packages, and use administrative privileges if needed.

Can I customize keybindings in VS Code?

Yes, you can customize keybindings in VS Code. Open the Command Palette (Ctrl+Shift+P), type “Preferences: Open Keyboard Shortcuts,” and modify shortcuts to match your preferences for a tailored workflow.

Instabuilt
Instabuilt

Crafting Unique Online Experiences with Custom Website Templates

Articles: 79