How to uninstall serverless? "npm uninstall -g serverless" is not working
Asked Answered
C

4

9

I cannot uninstall serverless. I have tried npm uninstall -g serverless but entering serverless -v after prints the version. I'm on Ubuntu Server 16.04.

Running which serverless prints /usr/bin/serverless.

I'm using n to have multiple versions of node installed so that might have something to do with it.

Colbert answered 7/5, 2019 at 2:5 Comment(2)
try which serverless to see the location you installed.Gussiegussman
it prints /usr/bin/serverlessColbert
P
11

Perhaps for different reasons I also wanted to remove global serverless and instead use a local version. Ultimately, regardless of installing serverless locally or globally, serverless CLI will still install serverless-components into your home directory. I think the whole point of installing serverless locally would be to pin serverless-components at a specific version number.

More to your question, here's how to remove a global install serverless and replace it with a local version.

Remove Globally Installed Serverless

Let's say you ran npm install -g serverless and you ran npx serverless. It has now installed any components listed in your serverless.yml file and updated your ~/.bashrc or ~/.bash_profile.

To remove it:

  1. npm uninstall -g serverless
  2. Open your ~/.bash_profile (or ~/.bashrc) and remove the line
# Added by serverless binary installer
export PATH="$HOME/.serverless/bin:$PATH"
  1. rm -rf ~/.serverless
  2. rm -rf ~/.serverlessrc
  3. rm -rf ~/.serverlesscomponentsrc

Use Serverless locally

The serverless-nextjs docs say:

Do not add @sls-next/serverless-component to your package.json file, it is not used and only the version in serverless.yml file is used.

But, therein lies the problem, you want to use a serverless-component (like serverless-next.js) but serverless is going to install it globally in your home directory.

To avoid that you can ignore the docs and do:

  1. npm install serverless --save-dev
  2. npm install @sls-next/serverless-component --save-dev
  3. Update serverless.yml to point directly to the component
# serverless.yml
nameOfMyApp:
 component: "./node_modules/@sls-next/serverless-component"
Pinkie answered 3/11, 2020 at 1:3 Comment(0)
H
2
  1. Check that you are not running a local version of serverless installed in the project directory.
  2. Manually delete the binary with rm -f /usb/bin/serverless
Hooke answered 21/5, 2019 at 23:41 Comment(2)
also it's to check if there's any serverless process running, kill it before you delete the folder. I had it on mac and had same problem, but my installation was in ~/.serverlessNicaea
Check location using which serverless. Mine was at /home/yourname/.serverless/bin/serverless in linux. Then try deletingCharlenacharlene
R
0

Try npm run with --force to overwrite files

npm install -g serverless --force
Rerun answered 10/10, 2022 at 12:52 Comment(0)
A
0

Solved:

sudo rm -rf /usr/local/lib/node_modules/serverless
sudo npm i -g serverless
Anastigmat answered 30/4 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.