VS Code Setup on Linux
Install VS Code via the official Microsoft APT repository, configure essential extensions, and fix common Linux-specific issues (font rendering, terminal path). Also covers .deb, Flatpak, and Snap methods.
What This Guide Achieves
| Goal | Status |
|---|---|
| Install VS Code on Ubuntu-based OS | Done |
| Configure essential extensions for Linux development | Done |
| Set up Stata integration (run do-files from VS Code) | Done |
| Configure keybindings for productivity | Done |
| Understand VS Code file locations on Linux | Done |
The Problem (Windows User Perspective)
VS Code on Linux works almost identically to Windows — same UI, same extensions, same settings. The main differences are:
- Installation method — no
.exeinstaller; you use.deborapt - Settings location —
~/.config/Code/User/instead of%AppData%\Code\User\ - Terminal integration — VS Code’s built-in terminal gives you a real bash shell
- Some extensions need Linux tools — automation tools like
wmctrl,xdotool,xclip(X11 only)
Installation
Method 1: Official APT Repository (Recommended)
This adds Microsoft’s repository directly so VS Code installs and updates through apt — no manual .deb downloads needed.
# 1. Install dependencies
sudo apt update
sudo apt install wget gpg apt-transport-https
# 2. Import Microsoft's GPG signing key
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft.gpg
# 3. Add the official repository
echo "deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null
# 4. Install
sudo apt update
sudo apt install code
Version installed on the tested setup: 1.121.0
Binary: /usr/bin/code → /usr/share/code/bin/code (APT symlink)
Future updates come automatically with sudo apt upgrade.
Method 2: Download .deb and Install
wget -O vscode.deb "https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64"
sudo apt install ./vscode.deb
rm vscode.deb
Installing from .deb also registers the Microsoft repository, so future updates come through sudo apt upgrade as well.
Method 3: Flatpak (Linux Mint Software Manager)
On Linux Mint, open Software Manager, search for “VS Code”, and click the green Install button for the Flatpak (Flathub) version. Unlike Snap, Flatpak is native to Mint and requires no terminal setup.
Method 4: Snap
sudo snap install code --classic
The
.deb/APT versions (Methods 1 and 2) have full file system access and are preferred for workflows involving clipboard tools (xclip,xdotool), external scripts, or system-level automation. Flatpak and Snap sandboxing can interfere with these tools.
Verify Installation
code --version
# Should print version info with date and commit hash
which code
# Should print: /usr/bin/code
Launch it from your application menu or by typing code in the terminal.
VS Code File Locations on Linux
| File | Linux Path | Windows Equivalent |
|---|---|---|
| User settings | ~/.config/Code/User/settings.json | %AppData%\Code\User\settings.json |
| Keybindings | ~/.config/Code/User/keybindings.json | %AppData%\Code\User\keybindings.json |
| Extensions | ~/.vscode/extensions/ | %USERPROFILE%\.vscode\extensions\ |
| Workspace settings | .vscode/settings.json (in project folder) | Same |
| Tasks | .vscode/tasks.json (in project folder) | Same |
Essential Extensions
For General Development
| Extension | ID | Purpose |
|---|---|---|
| GitLens | eamodio.gitlens | Git blame, history, and diff tools |
| Error Lens | usernamehw.errorlens | Show errors/warnings inline |
| Path Intellisense | christian-kohler.path-intellisense | Auto-complete file paths |
| Bracket Pair Colorizer | Built-in (enable in settings) | Visual bracket matching |
| Material Icon Theme | pkief.material-icon-theme | Better file icons in sidebar |
For Markdown and Documentation
| Extension | ID | Purpose |
|---|---|---|
| Markdown All in One | yzhang.markdown-all-in-one | Shortcuts, TOC generation, preview |
| markdownlint | davidanson.vscode-markdownlint | Markdown style linting |
For Stata Integration
| Extension | ID | Purpose |
|---|---|---|
| Stata Enhanced | kylebarron.stata-enhanced | Syntax highlighting for .do files |
| multi-command | ryuta46.multi-command | Chain multiple commands on one keybinding |
Install extensions from the command line:
code --install-extension kylebarron.stata-enhanced
code --install-extension ryuta46.multi-command
Stata Integration: Run Do-Files from VS Code
This is the most complex VS Code setup covered in these guides. The full details are in the Stata 19 Complete Guide, but here’s the summary.
Prerequisites
sudo apt install wmctrl xdotool xclip -y
These tools only work on X11 (Xorg), not Wayland. See the Display Server Guide for switching.
How It Works
Two custom shell scripts handle the VS Code → Stata communication:
| Script | Location | Purpose |
|---|---|---|
stata_run_do.sh | ~/.local/bin/ | Runs an entire .do file in Stata GUI |
stata_run_selection.sh | ~/.local/bin/ | Runs selected code in Stata GUI |
The workflow:
- VS Code copies code to clipboard (internally, no shell interpretation)
- Script writes clipboard to a temp
.dofile (avoids bash interpreting Stata syntax) - Script sends
do "/tmp/stata_selection_run.do"to Stata via clipboard + paste - Stata executes the temp file as a proper do-file
Keybindings
Add to ~/.config/Code/User/keybindings.json:
[
{
"key": "ctrl+enter",
"command": "workbench.action.tasks.runTask",
"args": "Run do-file in Stata GUI"
},
{
"key": "shift+enter",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.clipboardCopyAction",
{
"command": "workbench.action.tasks.runTask",
"args": "Run selection in Stata GUI"
}
]
},
"when": "editorTextFocus"
}
]
Usage
| Action | Keybinding |
|---|---|
| Run entire do-file | Ctrl+Enter |
| Run selected lines/chunk | Select code → Shift+Enter |
| Run a single line | Ctrl+L (select line) → Shift+Enter |
For the complete setup including script contents and tasks.json, see the Stata 19 Complete Guide Parts 5-7.
Useful Settings for Linux
Add to ~/.config/Code/User/settings.json:
{
// Use bash as default terminal
"terminal.integrated.defaultProfile.linux": "bash",
// Font with good Unicode support (check what's installed on your system)
"editor.fontFamily": "'Fira Code', 'Droid Sans Mono', 'monospace'",
// File associations
"files.associations": {
"*.do": "stata",
"*.ado": "stata",
"*.mata": "stata"
},
// Auto-save (optional — some prefer manual save)
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000,
// Trim trailing whitespace on save
"files.trimTrailingWhitespace": true,
// Show hidden files in file explorer
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true
}
}
Linux-Specific Tips
Opening VS Code from Terminal
# Open current directory
code .
# Open a specific file
code /path/to/file.py
# Open a specific folder
code /path/to/project
# Open VS Code with a new empty window
code -n
Using the Integrated Terminal
- Ctrl+` — Toggle the terminal panel
- Ctrl+Shift+` — Open a new terminal
- The terminal is a real bash shell — you can run any command directly
code filenamefrom the integrated terminal opens the file in a new tab
VS Code and File Permissions
Unlike Windows, Linux files have execute permissions. VS Code respects these:
- Scripts (
.sh) needchmod +xto be executable - VS Code’s terminal inherits your user permissions
- You can run
chmod +x filename.shdirectly from VS Code’s terminal
What Didn’t Work (and Why)
| Approach Tried | Why It Failed |
|---|---|
Using stata.* keys in VS Code settings.json | These keys only work if a specific Stata extension reads them — most don’t |
Passing ${selectedText} as shell argument for Stata | Bash interprets backticks, comments, and special characters in Stata code |
| Pasting raw Stata code into Stata’s command bar | Command bar executes one line at a time, doesn’t support block comments |
| Using Wayland with wmctrl/xdotool automation | These tools only work on X11 — must use Xorg session |
| Installing VS Code from snap for Stata workflow | Snap sandboxing can interfere with clipboard and window management tools |
Related Guides
- Stata 19 Complete Guide — Full Stata installation and VS Code integration
- Stata 19 MP with Antigravity IDE — Reuse the VS Code-style Stata workflow in Antigravity IDE
- Stata Cross-Platform — Making do-files work on Windows + Linux + macOS
- Display Server Guide — Why X11 is needed for automation
Discussion