Fix eacces: permission denied, unlink ‘/usr/local/bin/code’ Error

If you encounter the error message “EACCES: Permission denied, unlink ‘/usr/local/bin/code’” while using Visual Studio Code (VS Code), it indicates a permission issue when attempting to modify or remove the VS Code binary file.

This error commonly occurs when running VS Code with elevated privileges or during the installation or update process.

The error “EACCES: Permission denied, unlink ‘/usr/local/bin/code’” presents itself something like this:

EACCES: Permission denied, unlink '/usr/local/bin/code' Error On Mac
EACCES: Permission denied, unlink ‘/usr/local/bin/code’ Error On Mac

Or sometimes even like this, within VS Code itself:

EACCES: Permission denied, unlink '/usr/local/bin/code' Error In VS Code
EACCES: Permission denied, unlink ‘/usr/local/bin/code’ Error In VS Code

In this article, we will explore various solutions ranked from the best fixes to the worst, helping you resolve this error and regain control over your VS Code installation.

Let’s explore each solution in detail:

Understand the EACCES: Permission denied, unlink '/usr/local/bin/code' Error In VS Code


Before proceeding with the fixes, it is essential to understand the error message and its implications. The “EACCES: Permission denied, unlink ‘/usr/local/bin/code'” error typically indicates that the current user does not have sufficient permissions to modify or remove the VS Code binary file located in the ‘/usr/local/bin/’ directory.

Run VS Code with Sudo/Administrator Privileges


The quickest workaround is to run VS Code with elevated privileges using the ‘sudo’ command (on macOS and Linux) or by running it as an administrator (on Windows). Open a terminal or command prompt and execute the following command:

sudo code

or

Run as administrator

This allows VS Code to perform the necessary operations with the required permissions.

Change Ownership and Permissions of '/usr/local/bin/code'


If running VS Code with elevated privileges doesn’t resolve the issue, you can try changing the ownership and permissions of the '/usr/local/bin/code' file.

Open a terminal or command prompt and execute the following commands:

sudo chown $(whoami) /usr/local/bin/code
sudo chmod u+x /usr/local/bin/code

These commands change the ownership of the file to the current user and grant execute permissions.

Reinstall VS Code


If the previous solutions don’t work, consider reinstalling VS Code.

  1. First, uninstall the existing installation completely.
  2. Then, download the latest version of VS Code from the official website and follow the installation instructions.

This process will ensure a clean installation and may resolve any permission-related issues.

Use an Alternative Installation Method


Instead of installing VS Code system-wide, you can opt for a user-specific installation.

This method installs VS Code in your user directory, eliminating the need for elevated privileges and potential permission conflicts.

Refer to the VS Code documentation for instructions on how to perform a user-specific installation.

Seek Assistance from the VS Code Community


If you have exhausted all the above solutions and the error persists, it’s recommended to seek help from the VS Code community.

You can visit the official VS Code website, explore the community forums, or ask questions on platforms like Stack Overflow.

Experienced users and developers can provide additional insights and guidance for resolving the specific issue.

Final Thoughts


The “EACCES: Permission denied, unlink ‘/usr/local/bin/code'” error in VS Code can be resolved by running VS Code with sudo/administrator privileges, changing ownership and permissions of the ‘/usr/local/bin/code’ file, reinstalling VS Code, or considering alternative installation methods. By following the solutions outlined in this article, you should be able to overcome the error and continue using VS Code smoothly.

Please note that the specific error message may vary depending on the platform or environment. It’s advisable to refer to the official documentation. In this case, that might be the Github issues for VSCode.