'npm install always stuck at that exact time

I tried running $ npm install -g truffle and $npm install but it was constantly freezing at a particular point.

I also tried command yarn global add truffle but it was generating an error.

I looked for answers on the internet one of which suggested to run npm config set registry http://registry.npmjs.org/ and then npm install, but now I'm receiving the error:

EPERM: operation not permitted, unlink 'C:\Users\dell\AppData\Roaming\npm\node_modules\.staging'
yarn command now freezes after a point

I'm a beginner, please help.



Solution 1:[1]

It happens to me many times when I'm using Windows. What I did to make it continue after I felt that it was froze is

  1. Click the terminal. Make sure you set the focus on the terminal

  2. Hit ctrl + k

Solution 2:[2]

What you can do is run the command as an administrator.


For Windows (OP's Operating System)

To run the Command Prompt or PowerShell as an administrator, follow the steps below.

  1. Right-click on the Start button (don't open it).

  2. Select Windows PowerShell (Administrator), or Command Prompt (Administrator) (depending on which one shows for you) in the menu.

  3. Allow the operation by entering your password, or clicking Yes.

    UAC

    Retrieved from a Windows virtual machine.

  4. You can now type in your commands, which will run with administrative privileges.


For macOS/Linux

To run the command as an administrator, follow the steps below.

  1. Open the Terminal application.

  2. Run the command prefixed with sudo.

    $ sudo
    
  3. To run all of your commands as sudo, run:

    $ sudo -s
    

    You can then type in your commands, which will run under the sudo privileges.

Warning: The sudo command can only be run if you have the password for it. When you run a command with sudo, it will prompt you once for the password.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Arnav Thorat