Skip to main content

Command Palette

Search for a command to run...

How to Enable the code . Command for Portable VS Code on Your MacBook

Updated
3 min read
How to Enable the code . Command for Portable VS Code on Your MacBook

The MacBook Air 2017, while a classic, remains a capable machine for development, especially with a lightweight setup. If you're using a "portable" version of Visual Studio Code to save space or avoid a full installation, you might miss one of the most convenient workflow features: launching the editor from your terminal with the code . command.

By default, this command won't work because macOS doesn't know where to find your portable VS Code application. Fortunately, setting this up is a straightforward process. This guide will walk you through enabling the code . command for your portable VS Code setup.

The Goal

To open any project folder in VS Code directly from your terminal by typing code ..

The most effective way to solve this is by creating a symbolic link (or "symlink"). A symlink is essentially a powerful shortcut that tells your terminal where to find the VS Code executable file, which is hidden inside the .app package.

Step 1: Find the Full Path to Your Portable VS Code

First, you need the absolute path to where you've stored Visual Studio Code.app. Let's say you've placed it in a folder named Application inside your Documents folder.

You can get the full path easily:

  1. Open your Terminal application.

  2. Type cd (with a space after cd).

  3. Drag the Visual Studio Code.app file from your Finder window directly into the Terminal window. The full path will appear.

  4. For this guide, we'll assume the path is /Users/your-username/Documents/Application/Visual Studio Code.app. Remember to replace this with your actual path.

/usr/local/bin is the standard location on macOS for user-installed command-line tools. By placing our symlink here, the Zsh (or Bash) shell will automatically find it.

  1. Open your Terminal.

  2. Copy and paste the following command, making sure to replace the example path with your own path from Step 1. The quotes are important because of the spaces in the file name.

    Bash

     ln -s "/Users/your-username/Documents/Application/Visual Studio Code.app/Contents/Resources/app/bin/code" /usr/local/bin/code
    

Breaking down the command:

  • ln -s: The command to create a symbolic link.

  • "/path/to/your/Visual Studio Code.app/Contents/Resources/app/bin/code": This is the target—the actual executable file inside your VS Code application. you can check your path with pwd in folder vscode app. and you can add `/Contents/Resources/app/bin/code`

  • /usr/local/bin/code: This is the shortcut you are creating. When you type code in the terminal, it will point to the target file.

Step 3: Verify Your Setup

To ensure the changes take effect, open a new Terminal window. This allows the shell to recognize the new command.

Now, test it out:

  1. Navigate to any project directory.

    Bash

     cd ~/Desktop/my-project
    
  2. Run the command.

    Bash

     code .
    

Visual Studio Code should launch instantly, with the my-project folder opened in the editor.

Troubleshooting Common Issues

If you encounter an error, it's likely one of two things:

1. Error: zsh: command not found: code

This means /usr/local/bin is not in your system's PATH. You can fix this by adding it to your shell configuration file (.zshrc for Zsh).

Bash

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc

Then, open a new terminal or run source ~/.zshrc.

2. Error: ln: /usr/local/bin/code: No such file or directory

This means the /usr/local/bin directory doesn't exist on your system yet. You can create it with the following command. You will be prompted for your password.

Bash

sudo mkdir -p /usr/local/bin

After creating the directory, run the ln -s command from Step 2 again.

Conclusion

You have now successfully integrated your portable VS Code application with your terminal. This simple tweak drastically improves the development workflow on your MacBook Air 2017, proving that you don't need the latest hardware to have an efficient and productive coding environment. Happy coding!

More from this blog

F

Finlup ID | Sharing dunia teknologi dan coding

206 posts

Membedah Tren dan Teknologi yang Mengubah Dunia.