NVM exit status 145: The directory is not empty [Solved]

avatar
Borislav Hadzhiev

Last updated: May 10, 2023
3 min

banner

# NVM exit status 145: The directory is not empty [Solved]

The NVM error "exit status 145: The directory is not empty" occurs for multiple reasons:

  • Having an existing Node.js installation, e.g. at C:\Program Files (x86)\nodejs or C:\Program Files\nodejs
  • the installation path to the NVM directory contains spaces.
  • Forgetting to delete your nodejs folder after uninstalling Node.js.
shell
exit status 145: The directory is not empty exit status 1: Access is denied

In order to use NVM on Windows, you have to make sure that Node.js is not installed on your machine.

If you have a prior version of Node.js installed, it may cause the error because NVM doesn't have permission to remove it.

  1. Check if you have a nodejs installation at the following locations:
  • C:\Program Files (x86)\nodejs
  • C:\Program Files\nodejs
  1. If you find a nodejs folder at the specified locations, rename it.
shell
C:\Program Files (x86)\nodejs -> C:\Program Files (x86)\nodejsx C:\Program Files\nodejs -> C:\Program Files\nodejsx
  1. Try to run your nvm command.
shell
nvm install 18.16.0 nvm use 18.16.0

If the issue persists, delete the folder you just renamed, e.g. C:\Program Files (x86)\nodejsx or C:\Program Files\nodejsx.

You should also delete the following folders if they exist on your machine.

cmd
# 👇️ delete the following folders (if you have them) C:\Program Files (x86)\Nodejs C:\Program Files\Nodejs C:\Users\{User}\AppData\Roaming\npm C:\Users\{User}\AppData\Roaming\npm-cache C:\Users\{User}\.npmrc C:\Users\{User}\AppData\Local\Temp\npm-*

Try to run your nvm command after making sure that the folders don't exist.

shell
nvm install 18.16.0 nvm use 18.16.0

The NVM error "exit status 145: The directory is not empty" usually means that one of the following folders:

  • C:\Program Files (x86)\nodejs
  • C:\Program Files\nodejs

Is not empty and NVM doesn't have permission to overwrite it.

If the error persists and you have an existing Node.js installation, try to uninstall Node using the official installer.

Check out the following article if you need a step-by-step illustrated guide on how to uninstall Node.js.

You can also look for an existing Node.js installation in the Apps & Features menu:

  1. Click on the search field and type Apps & Features.

search apps and features

  1. Start the application.

  2. Search for Node.

  3. If you see Node.js, then click on the application and select Uninstall.

You can also try to uninstall Node.js using the Control Panel:

  1. Click on the search field, type Control Panel and start the application.
  2. Under Programs click on Uninstall a program.

click uninstall a program

  1. Look for Node.js in the list of programs.

  2. Right-click on it and select Uninstall.

If you need a step-by-step guide on how to install NVM on Windows, click on the link and follow the instructions.

# Run CMD as an administrator

If the issue persists, try to run CMD (Command Prompt) as an administrator.

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

windows run cmd as administrator

  1. Try to run your nvm command in the admin shell.
shell
nvm install 18.16.0 nvm use 18.16.0

# Enable your Windows device for development

If the issue persists, try to enable your device for development.

  1. Click on the search field and type Developer Settings.

search developer settings

  1. Start the application.

  2. Turn on Developer mode by switching on the toggle.

  3. Confirm if you get prompted.

turn on developer mode

  1. Try to run your nvm command in the admin shell.
shell
nvm install 18.16.0 nvm use 18.16.0

If the error persists, follow the step-by-step instructions on how to install NVM on Windows in this article.

You might have installed NVM using an incorrect path or you might've installed an older version of NVM that has issues with creating symbolic links.

Following the instructions in this article should resolve the issue.

# Conclusion

To solve the NVM error "exit status 145: The directory is not empty", make sure:

  1. You don't have an existing Node.js installation.
  2. You have deleted the C:\Program Files (x86)\nodejs or C:\Program Files\nodejs directories.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.