Visual Studio Code (VS Code) is a source-code editor developed by Microsoft for Windows, Linux, and macOS. Through the extensive work of the FreeBSD community, it has also been ported to FreeBSD and can be installed through binary packages. Setting up VS Code is simple and quick, and can be done from a fresh FreeBSD install.

Requirements:

 

Installation and Configuration:

Install the VS Code binary package:

# pkg install vscode

Note: As of this guide being written, Electron is blacklisted from the package builder. As this is a dependency of the vscode package, this may mean you will have to build VS Code from the ports collection:

# pkg install git
# git clone https://git.FreeBSD.org/ports.git /usr/ports
# git -C /usr/ports pull
# cd /usr/ports/editors/vscode
# make install clean

Exit the su root shell:

# exit

VS Code can be run directly from the terminal:

$ vscode

Additional language extensions can be installed directly through the VS Code application. Browse the available options through the “Extensions” button on the left of the client.

Note: Check the file locations where VS Code is configured to find them. rust-analyzer, for instance, will give an error because the VS Code extension searches a different file than where it is stored on FreeBSD. To quickly fix this issue:

$ whereis rust-analyzer 
rust-analyzer: /usr/local/bin/rust-analyzer


Navigate to the VSCode settings gear in the bottom left and open the .json settings file.


Add the correct path to the rust binary:
“rust-analyzer.server.path”: “/usr/local/bin/rust-analyzer”

Using VS Code:

Let’s use VS Code to create a simple “hello world” script using Python:

Start by creating and opening a folder, either using the dropdown menu under ‘File’ or on the welcome page. Click “Create Folder” at the top right of the client. We’ll store the text files we create here. Once opened, VS Code will show the empty folder in the “Explorer” section.

Create a new file in this folder, VS Code will ask for either a file type or file name. In this example, I named it PythonTest.py. 

VS Code will correctly identify the file as Python, but further support will be needed to provide IntelliSense (code auto-completion and quick info), formatting, and debugging.

Navigate to the ‘Extensions’ tab on the left of the client, and install the ‘Python’ language support extension.

Now when we try to type a simple print command in the Python file we created, VS Code will autocomplete and show error messages

Type a simple hello world command:

Save your changes under ‘File’.

Tip: Enable ‘Auto Save’ so you don’t have to manually save each time changes are made.

 

Then, run and debug the file. Either by pressing ‘F5’ or selecting ‘Run Python File’ at the top right of the client.

Troubleshooting VS Code:

While this guide aims to be as broad as possible, users may still run into issues when installing the vscode package. There’s a wide range of possible errors, from unsupported packages to known bugs to unsupported hardware.

Note: The vscode port is currently only supported for the amd64 architecture; if you run into an error mentioning unsupported architecture, confirm that the system is amd64:

$ uname -a

1. Search the Problem Report (PR) database for known fixes pending implementation. This is also useful to find existing bugs that other users have encountered.

2. If none of the above works, contact the port maintainer directly. Port maintainers are listed at the top of the FreshPorts page. An easy way to get visibility on an issue is to post to the freebsd-ports mailing list and CC the maintainer. Ask if they know of any issues and include the output before the error.