Sub topic 2
Installing VS Code
This chapter covers installing Visual Studio Code (VS Code), checking that the install worked, and preparing the editor for the Salesforce tools you add in later chapters. It assumes you can run commands in a terminal and know basic VS Code concepts such as the Explorer, the Command Palette, and the integrated terminal. It does not assume you have installed VS Code before.
What VS Code does in this setup
VS Code is the editor that hosts everything else. It does not know how to talk to Salesforce on its own. The Salesforce Extension Pack, the Salesforce CLI, and a Java JDK each supply one piece, and VS Code is where they come together.
Two details of how VS Code is built matter for the rest of this tutorial:
- VS Code starts extensions as separate processes. An extension can launch a command-line tool or a Java program, and it finds those programs through the
PATHenvironment variable that VS Code itself inherited when it started. - Because the
PATHis captured at startup, a tool you install while VS Code is running is often invisible to it until you restart the editor completely.
The second point causes many of the setup problems you will see later, so keep it in mind.
Choosing a build
VS Code is published in two channels, and most platforms have a few packaging choices.
| Choice | Options | Recommendation for Apex work |
|---|---|---|
| Release channel | Stable, Insiders | Stable. Insiders updates daily and can break extensions. |
| Install scope (Windows) | User Installer, System Installer, zip | User Installer, unless your organization requires a system-wide install. |
| Architecture | x64, Arm64 | Match your CPU. Arm64 is correct for Apple silicon and Windows on Arm. |
| Package type (Linux) | .deb, .rpm, Snap, tarball | The .deb or .rpm package from the official site. |
A user-scope install does not need administrator rights and updates itself quietly in the background. A system-wide install needs administrator rights for each update, so some teams manage it with their own software deployment tools.
The Salesforce extensions are tested against the Stable channel. Use Stable unless you have a specific reason not to.
Installing on each platform
Download VS Code only from the official site, https://code.visualstudio.com. Package managers are also fine, because they pull the same official builds.
Windows
Run the installer you downloaded. On the "Select Additional Tasks" page, enable these options:
- Add to PATH (requires shell restart). This makes the
codecommand available in terminals. It is usually on by default. - Add "Open with Code" action to Windows Explorer file context menu. This is optional, but it is handy for opening project folders.
You can also install with winget:
winget install --id Microsoft.VisualStudioCodemacOS
Download the .zip for your architecture, extract it, and drag Visual Studio Code.app into the Applications folder. If you run it from another folder, such as Downloads, macOS may keep it in a quarantined state and updates may fail. With Homebrew, you can install it with one command:
brew install --cask visual-studio-codeLinux
On Debian or Ubuntu, install the .deb package with apt, which also resolves dependencies:
sudo apt install ./code_*.debOn Fedora or RHEL-based systems, install the .rpm package with dnf:
sudo dnf install ./code-*.rpmThe Linux packages add the code command to your PATH automatically. They also register a package repository so that your system's normal updates keep VS Code current.
Making the `code` command available
The code command opens files and folders in VS Code from a terminal. The later chapters rely on it. For example, the project chapter ends with code . to open a new project folder.
On Windows and Linux, the installer normally sets this up. On macOS, you may need to add it yourself:
- Open VS Code.
- Open the Command Palette with
Cmd+Shift+P. - Run Shell Command: Install 'code' command in PATH.
- Open a new terminal window.
On Windows, if you left "Add to PATH" unchecked during installation, run the installer again with it checked, or add the bin folder of your VS Code install to the PATH yourself.
Verifying the install
Open a new terminal. A terminal that was already open will not see changes to PATH.
code --versionThe output has three lines: the VS Code version, the commit hash of the build, and the CPU architecture. A typical result looks like this, though your numbers will differ:
1.95.3
f1a4fb101478ce6ec82fe9627c43efbf9e98c813
x64The architecture line is worth a glance. If you are on an Arm machine and see x64, you installed the Intel build and it is running under emulation, which is slower.
If the shell reports command not found or 'code' is not recognized, the code command is not on your PATH. Go back to the previous section. Do not move on until this works, because the next chapters assume it.
You can also list installed extensions as a quick check that the command-line interface works end to end:
code --list-extensionsOn a fresh install the list is empty. After you install the Salesforce Extension Pack, it will contain several salesforce.* identifiers.
First launch and the settings you should know
When VS Code first opens, it shows a Welcome page. You do not need to complete the walkthroughs. Two areas are worth knowing now, because later chapters use them.
The Command Palette
Most Salesforce actions appear as commands that start with SFDX:. You reach them through the Command Palette, which opens with Ctrl+Shift+P on Windows and Linux or Cmd+Shift+P on macOS. Type SFDX and the list filters to the Salesforce commands once the extensions are installed.
Settings
VS Code keeps settings at two levels:
| Level | Where it lives | Applies to |
|---|---|---|
| User | A `settings.json` file in your user profile | Every project you open |
| Workspace | `.vscode/settings.json` inside a project | Only that project |
A workspace setting overrides a user setting. This matters for Apex work because a setting such as the Java home path may differ per machine, so you usually want it at the user level. Settings that describe the project can live in the workspace, where they can be committed to source control.
To edit the raw JSON, run Preferences: Open User Settings (JSON) from the Command Palette. VS Code accepts comments and trailing commas in this file, which plain JSON does not.
Opening a terminal inside VS Code
The integrated terminal is where you will run sf commands. Open it with ` Ctrl+ ` (the backtick key). It opens in the folder of your current project, so relative paths such as force-app` behave as expected.
The integrated terminal gets its PATH from the way VS Code was launched. This leads to a common surprise.
On macOS, there is a second variation. If you start VS Code from the Dock or Spotlight, it takes its environment from the login session, not from your shell startup files. A PATH change you made in ~/.zshrc may be visible when you launch with code . from a terminal but not when you launch from the Dock. If an extension cannot find a tool that works fine in your terminal, try launching VS Code with code . from that terminal to see whether the problem goes away.
Keeping VS Code up to date
VS Code updates itself by default on Windows and macOS. A notice appears when a new version is ready, and a restart applies it. On Linux, the package manager handles updates.
Salesforce extensions require a minimum VS Code version, which is listed on each extension's Marketplace page. If the Extension Pack refuses to install or reports an incompatibility, check your version with code --version and update first. This is the most common reason for an install error that mentions the "engine".
You can check for updates manually from Help > Check for Updates on Windows and Linux, or Code > Check for Updates on macOS.
Working in restricted or managed environments
Some company machines limit what you can do. Three situations come up often:
- No administrator rights. Use the User Installer on Windows, or extract the macOS app into a folder you own.
- A proxy or firewall. The Extensions view downloads from the Visual Studio Marketplace. If your network blocks it, set the
http.proxysetting in VS Code, or ask your administrator to allow the Marketplace domains. The.vsixfile workaround is covered in the troubleshooting chapter. - VS Code alternatives. Forks of VS Code, such as VSCodium, use a different extension registry. The Salesforce extensions are published on the Visual Studio Marketplace, so they may not appear there. Stay with the official build unless you are prepared to install extensions from files.
Common mistakes
- Installing VS Code but never testing
code --version. A missingPATHentry then shows up later as a confusing failure in a different step. - Testing in a terminal that was open before the install. Always open a new one.
- Running the macOS app from the Downloads folder, which prevents automatic updates.
- Choosing the Insiders build for convenience. It gets daily changes, and a regression can stop an extension from activating.
- Installing the x64 build on an Arm machine, which works but runs through emulation.
Checkpoint
Before moving on, you should be able to confirm the following:
code --versionprints a version, a commit, and an architecture that matches your machine.code --list-extensionsruns without an error.- The Command Palette opens, and you can find Preferences: Open User Settings (JSON).
- The integrated terminal opens with `
Ctrl+``.
The next chapter installs the Salesforce CLI, the second tool that the extensions depend on. Install it with VS Code closed, or plan to restart VS Code afterward.
Exercise
You install the Salesforce CLI while VS Code is open. In a regular system terminal, sf --version works, but the VS Code integrated terminal says the command is not found. What is the cause, and what is the fix?
Show answer
VS Code captured its PATH when it started, before the CLI was installed, so the integrated terminal and the extensions use the old value. Quit VS Code completely (not just close the window) and start it again. On macOS, launching it with code . from a terminal that already has the updated PATH also works.
Exercise
On macOS, code --version prints command not found even though VS Code is installed in the Applications folder. How do you fix it, and how do you confirm it worked?
Show answer
Open VS Code, open the Command Palette with Cmd+Shift+P, and run "Shell Command: Install 'code' command in PATH". Then open a new terminal window and run code --version. A version, a commit hash, and an architecture line confirm the fix.