How to Install VSCode on Ubuntu: Step-by-Step
Whether you’re diving into coding or configuring your development environment, knowing how to install VSCode on Ubuntu is your first step. Visual Studio Code is a powerful and versatile code editor widely utilized across various Linux distributions, including Ubuntu.
As an open-source tool developed by Microsoft, it offers seamless integration with GitHub, extensive support through extensions, and robust performance for Bash scripting, Python, and Node.js development.
Setting up VSCode on Ubuntu might seem daunting, but it’s straightforward with the right guidance.
In this article, you’ll discover the exact commands to execute in the terminal, explore different methods such as using the APT command, and understand the nuances between the Snap package and the .deb package installations.
By the end, you’ll have Visual Studio Code up and running, configured for your development needs, and ready to enhance your workflow with essential add-ons and integrations.
How to Install VSCode on Ubuntu:Quick Workflow
Sure! Here’s the revised guide on how to install Visual Studio Code (VSCode) on Ubuntu without citations.
Method 1: Install VSCode Using Snap
Snap packages are easy to install and manage. Follow these steps:
- Open Terminal: Press
Ctrl + Alt + T
to launch the terminal. - Install VSCode: Execute the following command:bash
sudo snap install --classic code
- Verify Installation: Check if VSCode is installed correctly by running:bash
code --version
- Launch VSCode: Start VSCode by typing
code
in the terminal or finding it in your application menu.
Method 2: Install VSCode Using APT
This method involves adding the Microsoft repository and installing via APT:
- Open Terminal: Launch the terminal.
- Update Package List: Run:bash
sudo apt update
- Install Required Dependencies: Ensure you have necessary dependencies:bash
sudo apt install software-properties-common apt-transport-https wget -y
- Add Microsoft GPG Key: Import the GPG key for package verification:bash
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
- Add VSCode Repository: Add the repository to your system:bash
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
- Update Package List Again: Refresh your package list:bash
sudo apt update
- Install VSCode: Finally, install VSCode with:bash
sudo apt install code
- Verify Installation: Check the installation:bash
code --version
- Launch VSCode: Start it by typing
code
in the terminal or from the application menu.
Method 3: Install VSCode Using GUI
If you prefer a graphical interface:
- Open Ubuntu Software Center: Click on the “Show Applications” button and select “Ubuntu Software.”
- Search for VSCode: Use the search bar to find “Visual Studio Code.”
- Install VSCode: Click on the “Install” button and enter your administrator password when prompted.
- Launch VSCode: Once installed, you can open it from the application menu.
Uninstalling Visual Studio Code
If you need to uninstall VSCode, use one of the following methods:
Uninstall via Terminal
- Open Terminal.
- Run:bash
sudo apt remove --purge code
- To remove any residual configuration files, execute:bash
sudo apt autoremove
Uninstall via GUI
- Open Ubuntu Software Center.
- Search for “Visual Studio Code.”
- Click on it and select “Remove,” then confirm your choice.
By following these steps, you can easily install and manage Visual Studio Code on your Ubuntu system, enhancing your coding experience with this powerful editor.
Prerequisites for Installing VS Code on Ubuntu
System Requirements
Supported Ubuntu versions and system specifications
Visual Studio Code (VSCode) requires a compatible Ubuntu version. Ubuntu 16.04 LTS, 18.04 LTS, and 20.04 LTS are well-supported. Ensure your system has at least 1 GB of RAM and 150 MB of free disk space.
Ensuring access to administrator privileges
Before you start, verify that you have administrator privileges. You’ll need these to install and configure packages. Use the sudo
command for administrative tasks. Without proper permissions, installation will fail.
Network requirements for downloading packages
Make sure your network connection is stable. Slow or unstable networks can disrupt the download and installation process. Ensure your firewall settings allow access to the APT and Snap repositories for smooth package retrieval.
Recommended Preparation Steps
Updating Ubuntu system packages
First, update your system packages to avoid conflicts. Open the Terminal:
sudo apt update && sudo apt upgrade
This ensures you have the latest security updates and package versions.
Installing basic dependencies (e.g., wget, gpg) if needed
Check for and install essential dependencies. wget
and gpg
are crucial for downloading and verifying installation files. If these aren’t installed, use:
sudo apt install wget gpg
These tools facilitate secure and efficient software retrieval.
Setting up software sources for Microsoft’s repositories
To access the Visual Studio Code repository, add Microsoft’s repository to APT sources. First, import the Microsoft GPG key:
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 /etc/apt/trusted.gpg.d/
Next, add the Microsoft repository to your system’s package source list:
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
Finally, update your package list to include the new repository:
sudo apt update
Installation Methods for Visual Studio Code on Ubuntu
Installing VS Code via the Ubuntu Software Center (GUI)
Steps to access and navigate the Ubuntu Software Center
Start with the easiest method if you’re new to Ubuntu. Open the Ubuntu Software Center. Click the app launcher (bottom left corner) and type Software. Select Ubuntu Software from the search results.
Searching for Visual Studio Code in the application list
In the Software Center, type Visual Studio Code in the search bar.
Click Visual Studio Code when it appears. You’ll see the app details, reviews, and screenshots.
Installing VS Code and verifying the installation
Hit the Install button. Authenticate with your password. Once installed, you can find VSCode
in your Applications list. Open it to verify everything’s working.
Benefits and limitations of the GUI method
The GUI method is user-friendly. No commands needed. However, it may lag in updates. Also, limited customizability compared to terminal installations.
Installing VS Code as a Snap Package
Overview of Snap packages and their advantages
Snap packages are great for automatic updates and sandboxing. Keeps everything secure. Think of it like app containers – isolated from the system, reducing risk.
Step-by-step guide to installing VS Code via Snap
Use the Terminal for this. Open it up and type:
sudo snap install --classic code
Wait for the download and installation to complete.
Verifying installation and updating VS Code through Snap
To check, type:
code
in the Terminal. It should open. Snap handles updates automatically but to force an update:
sudo snap refresh code
Known issues and compatibility considerations with Snap on Ubuntu
Snaps can be heavy on disk space. Some users report slower startup times and minor compatibility quirks with some system themes.
Installing VS Code Using the APT Package Manager
Adding the Microsoft repository to your system
First, add Microsoft’s repository and GPG key. Open Terminal and execute:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Add the repository:
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
Installing VS Code through APT
Update your package list:
sudo apt update
Install Visual Studio Code:
sudo apt install code
Updating the system repository and dependencies
By regularly updating your system packages, you ensure smooth installation and subsequent updates:
sudo apt update && sudo apt upgrade
Running the installation command and verifying the version
Run code
in Terminal to launch it. To verify the version:
code --version
Advantages of the APT method for advanced users
APT gives you control. It’s lean on system resources and integrates well with your system’s package management. Ideal for those comfortable with command-line workflows.
Configuration and Setup after Installation
Initial Setup and Interface Customization
Launching VS Code for the first time
Open the terminal. Type code
and hit Enter. Visual Studio Code should launch. If everything is set up correctly, the welcome screen greets you.
Navigating the main interface and setting up the workspace
Familiarize yourself with the layout. On the left, the sidebar houses your Explorer, Search, Source Control, Debug, and Extensions tabs. The main area is your playground: the editor. Use Ctrl + ~ to toggle the integrated terminal. It’s all about efficiency.
Customizing themes, fonts, and layout to optimize workflow
Head to File > Preferences > Color Theme. Dark mode, light mode – it’s your call. Tweak fonts in File > Preferences > Settings > Text Editor > Font. Space and readability matter.
Arrange your panels and sidebar to suit your workflow. Drag, drop, resize – make it yours.
Essential Extensions for Development
Recommended extensions for popular languages (e.g., Python, JavaScript, C++)
Extensions elevate your coding. For Python, grab the Python extension by Microsoft. JavaScript enthusiasts; ESLint is a must. For C++, C/C++ by Microsoft works wonders.
Navigate to the Extensions tab on the sidebar. Search and install.
Installing and managing extensions through VS Code’s extension marketplace
Click the Extensions tab. Type the extension name. Hit Install. Managing extensions is a breeze. Disable, enable, and uninstall them as your projects evolve.
Configuring extensions for linting, debugging, and formatting
Each extension comes with its own settings. For example, to configure Python for linting and debugging, go to File > Preferences > Settings. Under Extensions, find Python. Adjust settings like linting rules and debug configurations here.
Setting VS Code as the Default Text Editor
Using xdg-open to set VS Code as the default editor
Run the following command to set VS Code as your default editor:
xdg-mime default code.desktop text/plain
This command makes VS Code your go-to for opening text files.
Configuring Debian alternatives to prioritize VS Code
Debian alternatives system lets you set VS Code as the priority editor. Use:
sudo update-alternatives --set editor /usr/bin/code
Using VS Code on Ubuntu: Key Features and Functionalities
Integrated Version Control with Git
Setting up Git integration within VS Code
Open VS Code and look for the Source Control icon in the Activity Bar. Click it.
If Git isn’t already installed on your Ubuntu system, first install it:
sudo apt install git
Configure Git with your username and email:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Reload VS Code. It should now recognize Git, showing your repositories and changes.
Basic version control operations (commit, push, pull)
Inside VS Code’s Source Control tab, you’ll see your files. Stage changes by clicking the + icon next to each file. Once ready, type your commit message in the input box at the top and hit Commit.
For pushing changes to a remote repository:
git push
Pull updates from the remote repository directly within VS Code:
git pull
Managing branches and resolving conflicts within VS Code
Branch management is straightforward. In the Source Control tab, switch branches using the dropdown at the top. Create new branches as needed.
To handle merge conflicts, VS Code highlights conflicting sections, showing incoming and current changes. Choose which lines to keep, stage the resolved changes, and commit.
Terminal and Command Line Interface
Accessing the integrated terminal for command-line tasks
Toggle the integrated terminal with Ctrl + `. Multiple terminal sessions can be added via the + icon. It supports Bash by default but can be configured for other shells.
Tips for navigating and customizing the terminal experience
Adjust the terminal size by dragging the top border. Customize the appearance through File > Preferences > Settings > Terminal. Personalize font size, color themes, and cursor styles.
Using terminal commands to enhance coding productivity
Common commands streamline workflow. The code
command opens files directly from the terminal:
code myfile.py
Frequently used commands like mkdir
for creating directories, ls
for listing files, and sudo
for administrative tasks keep you productive. Integrate tasks like building projects or running tests directly in the terminal to stay within the VS Code environment.
Debugging and Code Testing
Overview of the built-in debugging tools in VS Code
VS Code comes equipped with robust debugging tools. The Debug icon in the Activity Bar opens the debug panel. It allows setting breakpoints, watching variables, and stepping through code.
Configuring debuggers for various languages
Different languages require different setups. For Python, install the Python extension. Create a launch.json
file in the .vscode
folder to configure the debugger:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
For JavaScript, use the built-in Node.js debugger.
Tips for optimizing the debugging and testing workflow
Use breakpoints efficiently. Set them to pause code execution at critical points. Inspect variables by hovering over them in the editor. Utilize the Debug Console for evaluating expressions on the fly. Arrange your layout to always keep the debug panel visible while coding, ensuring quick access to debugging tools.
Advanced Usage and Optimization on Ubuntu
Setting Up Development Environments
Using Docker containers with VS Code on Ubuntu
Containers! Ah, the best way to sandbox your development environment.
First, install Docker:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Once Docker’s up and running, install the Remote – Containers extension in VS Code. Open your project folder in VS Code and use the Command Palette (Ctrl+Shift+P
), search for Remote-Containers: Open Folder in Container.
VS Code will boot your project inside a Docker container. Lifesaver for consistent environments.
Configuring remote development environments via SSH
If you’re working on remote servers, configuring SSH is the way to go. Install the Remote – SSH extension from the marketplace.
In the Command Palette, type Remote-SSH: Connect to Host. Add your SSH target. VS Code will open a new window connected to the remote environment.
Edit files directly on the remote machine. Seamless.
Integrating with Windows Subsystem for Linux (WSL) if needed
WSL bridges the gap between Windows and Linux.
Ensure WSL is set up on your Windows machine and install Ubuntu from the Microsoft Store.
In VS Code, install the Remote – WSL extension. Fire up the Command Palette and use Remote-WSL: New Window. Your VS Code is now running in the WSL environment, giving access to Linux tools on Windows.
Managing Large Projects and Workspaces
Configuring settings for large file handling (e.g., file watching limits)
Big projects need careful setups. Increase file watching limits:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
This avoids missing file changes in large projects.
Excluding unnecessary files and directories (node_modules, .git)
Keep VS Code snappy by ignoring large directories. Add ignore patterns in your settings.json
:
"files.exclude": {
"node_modules": true,
".git": true
}
These won’t clutter your Explorer and maintain performance.
Optimizing performance by adjusting VS Code settings
Performance tweaks matter. Disable unnecessary features. In settings.json
:
"editor.minimap.enabled": false,
"extensions.ignoreRecommendations": true
Lean and mean, just the way we like it.
Enhancing Productivity with Key Bindings and Shortcuts
Customizing keyboard shortcuts to improve efficiency
Efficiency is king. Head to File > Preferences > Keyboard Shortcuts.
Remap commands to your liking. For example, quickly toggle the integrated terminal:
{
"key": "ctrl+`",
"command": "workbench.action.terminal.toggleTerminal"
}
Using built-in VS Code commands for quick navigation
Commands are your best friend. Open the Command Palette with Ctrl+Shift+P. Navigate to anything. Go to File, Symbol, or Line. It’s all fingertips away.
Integrating with task runners and automation tools (e.g., Make, npm)
Automate repetitive tasks. Configure task runners:
Task configuration in .vscode/tasks.json
for npm scripts
:
{
"version": "2.0.0",
"tasks": [
{
"label": "npm install",
"type": "shell",
"command": "npm install",
"group": "build",
"problemMatcher": []
}
]
}
Uninstalling VS Code from Ubuntu
Removing VS Code Installed via Snap
Command to remove the Snap package
To get rid of VS Code installed via Snap, open your terminal. Type:
sudo snap remove code
This command tells Snap to remove VS Code from your system.
Cleaning up residual configuration files
Snap packages sometimes leave behind config files. To clean them up:
rm -rf ~/snap/code
This ensures no leftover files are cluttering your system.
Removing VS Code Installed via APT
Commands to remove the package and dependencies
If you installed VS Code using APT, start with:
sudo apt-get remove code
This command removes the main package. To get rid of any dependencies that are no longer needed:
sudo apt-get autoremove
Ensures your system remains lean.
Purging configuration and residual files
To completely wipe out all configurations and files associated with VS Code:
sudo apt-get purge code
Follow this with:
sudo apt-get autoremove --purge
Cleans up anything that might have been left behind.
Removing VS Code Installed via the Ubuntu Software Center
Steps to uninstall using the Ubuntu Software Center GUI
Open the Ubuntu Software Center. Click on the Installed tab. Look for Visual Studio Code. Click Remove.
Confirming removal and checking for leftover files
To ensure everything is gone, open your terminal and list any files:
ls ~/.config/Code
If any files appear, delete them:
rm -rf ~/.config/Code
FAQ on How To Install VSCode On Ubuntu
What’s the easiest way to install VSCode on Ubuntu?
To install VSCode on Ubuntu, the easiest method is through the Snapcraft store. Open your terminal and type sudo snap install code --classic
. This command fetches the Snap package and installs it, ensuring you get the latest version directly from Microsoft.
Can I install VSCode using the APT command?
Yes, you can use the APT command. First, add the Microsoft repository:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
Then, install VSCode with:
sudo apt update
sudo apt install code
What’s the difference between Snap and .deb installation?
The Snap package is self-contained, easy to install, and automatically updates. The .deb package, on the other hand, integrates more closely with the system, allowing the use of APT for updates but might require manual updates. Both methods result in a fully functional code editor.
How to verify VSCode installation?
After installing, you can verify by launching Visual Studio Code. Simply type code
in the terminal or find “Visual Studio Code” in your app menu. If it starts without issues, you’re all set. To check the version, use code --version
.
Can I uninstall VSCode if needed?
Indeed, you can uninstall it. For the Snap version, use: sudo snap remove code
. For the .deb package, use: sudo apt remove code
. This will remove the code editor from your Ubuntu system.
How to install VSCode extensions?
Once VSCode is installed, open it and navigate to the Extensions Marketplace within the editor. You can search for extensions like Python or GitHub support and click “Install”. Extensions enhance your coding environment significantly.
Is there an offline installer for VSCode?
Unfortunately, VSCode is typically installed online through either the Snapcraft store or the Microsoft repository. However, you can download the .deb package from the Visual Studio Code website, transfer it, and install it using sudo dpkg -i code.deb
.
What are the system requirements for running VSCode?
For Ubuntu, you’ll need a system running Ubuntu 16.04 / 18.04 / 20.04 / 22.04 or later, 64-bit architecture, 2GB of RAM, and around 200MB of storage space for the installation. A good internet connection is also recommended for downloading extensions.
Can I use VSCode on older Ubuntu versions?
VSCode supports Ubuntu 16.04 and later. For versions older than this, the installation might not be straightforward, and official support is limited. It’s advisable to upgrade your Ubuntu to a more recent version for the best experience.
How to update VSCode after installation?
For the Snap version, it updates automatically. For the .deb package, simply run sudo apt update && sudo apt upgrade
from your terminal. This keeps VSCode and all installed extensions up to date, ensuring you benefit from the latest features and fixes.
Conclusion
Installing VSCode on Ubuntu is a straightforward process when you know the right steps. By following this guide, you’ve learned how to install VSCode on Ubuntu using both the Snap package and the APT command. This ensures your development environment is set up to support various coding languages like Python and Node.js with ease.
You now have the ability to install and manage extensions from the Extensions Marketplace, enhancing your coding experience. Whether you’re using Snapcraft or the Microsoft repository, updating and maintaining VSCode is simple and efficient. Uninstallation is also a breeze, giving you flexibility.
To recap:
- Snap Package:
sudo snap install code --classic
- APT Method: Add the repository, then
sudo apt install code
- Verify: Launch and check with
code --version
- Uninstall:
sudo snap remove code
orsudo apt remove code
Your Ubuntu workstation is now ready for efficient and effective coding with Visual Studio Code. Happy coding!
- How to Check Screen Time on iPhone - December 11, 2024
- How to Autoformat in VSCode Effortlessly - December 10, 2024
- How to Turn Off Restrictions on iPhone - December 10, 2024