FG
🛠️ Developer ToolsMicrosoft

[BUG] npm update --global fails: npm ERR! global requires an add or rm option

Freshabout 19 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

Current Behavior: [code block] Expected Behavior: Before v7.0.0, running `npm update --global` would update all the packages installed globally which are outdated. Steps To Reproduce: Install an outdated global package, and try to update all the packages. Environment: - OS: Ubuntu 20.04.1 - Node: 12.19.0 - npm: 7.0.0

Error Output

Error: global requires an add or rm option

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix npm update --global command for version 7.0.0

Medium Risk

In npm version 7.0.0, the behavior of the 'npm update --global' command changed, requiring explicit add or rm options for global package management. This was a significant shift from previous versions where 'npm update --global' would update all outdated global packages without additional parameters.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Check for outdated global packages

    Before updating, check which global packages are outdated by running the command. This will help you identify what needs to be updated.

    bash
    npm outdated --global --depth=0
  2. 2

    Update specific global packages

    Since 'npm update --global' is not functioning as expected, you can update each outdated package individually using the following command format.

    bash
    npm install --global <package-name>
  3. 3

    Create a script to automate updates

    To streamline the process of updating all global packages, create a shell script that runs the update command for each outdated package identified in step 1.

    bash
    for pkg in $(npm outdated --global --parseable | awk -F'/' '{print $NF}'); do npm install --global $pkg; done
  4. 4

    Consider downgrading npm

    If you prefer the previous behavior, consider downgrading npm to a version prior to 7.0.0 where 'npm update --global' worked as expected.

    bash
    npm install -g npm@6

Validation

Confirm the fix by running 'npm outdated --global --depth=0' again to ensure no outdated packages remain. Additionally, verify that the packages have been updated by checking their versions with 'npm list --global --depth=0'.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejsrelease-7.xbug