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:
npm uninstall -g serverless
- Open your
~/.bash_profile
(or ~/.bashrc
) and remove the line
# Added by serverless binary installer
export PATH="$HOME/.serverless/bin:$PATH"
rm -rf ~/.serverless
rm -rf ~/.serverlessrc
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:
npm install serverless --save-dev
npm install @sls-next/serverless-component --save-dev
- Update
serverless.yml
to point directly to the component
# serverless.yml
nameOfMyApp:
component: "./node_modules/@sls-next/serverless-component"
which serverless
to see the location you installed. – Gussiegussman/usr/bin/serverless
– Colbert