windowsnpmvisual-studio-code

How can I run a command with administrator rights with Visual Studio code terminal?


The new version 1.2.0 includes a terminal, but when I try to install any pack with Node.js, I get the "npm ERR! code EPERM" that I usually solve by right-clicking and running it as administrator. How can I do that in the Visual Studio Code terminal? Is there something like sudo for Linux?

Visual Studio Code terminal


Solution

  • Option 1 - Easier & Persistent

    Running Visual Studio Code as Administrator should do the trick.

    If you're on Windows you can:

    1. Right click the shortcut or application (EXE file)
    2. Go to Properties
    3. Compatibility tab
    4. Check "Run this program as an administrator"

    There is a caveat to it though

    Make sure you have all other instances of Visual Studio Code closed and then try to run as Administrator. The Electron framework likes to stall processes when closing them, so it's best to check your Task Manager and kill the remaining processes.

    Related changes in the codebase

    Option 2 - More like Sudo

    If for some weird reason this is not running your commands as an Administrator, you can try the runas command. Microsoft: runas command

    Examples

    Notes