DEV Community

David
David

Posted on

How to use NVM in Laravel Forge

  1. SSH to forge server and run this command
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
Enter fullscreen mode Exit fullscreen mode
  1. In forge site deployment script. add this script to install and change the version
echo 'configuring nvm...';
. ~/.nvm/nvm.sh
nvm install v20.0.0
nvm use v20.0.0

echo 'Running > npm install';
npm install

echo 'Running > npm run build';
npm run build
Enter fullscreen mode Exit fullscreen mode

Top comments (5)

Collapse
 
xwero profile image
david duymelinck • Edited

Why would you want nvm on you server?

Nvm is a development tool which allows you to use different node version in diffferent projects or branches.

If you want a new node version on you server. Just update it as you would php.

Collapse
 
repl6669 profile image
Jakub Theimer

What about running multiple applications on one instance?

Collapse
 
xwero profile image
david duymelinck

If it is really needed to have multiple node versions. I would install the versions that are needed, and use the full path to start the server.
I would only do this as a temporary fix, and update the code to the newest version as soon as possible.

I want servers to only have the essential tools. I even remove npm from the server, do the build process in the CI flow and move the build code to the server.

Thread Thread
 
adampatterson profile image
Adam Patterson

That's very specific to your deployment process though.

It's possible to run multiple sites on a single server and Forge with Git Deployments could easily have projects with unique versions of PHP and Node.

Thread Thread
 
xwero profile image
david duymelinck

I know it is possible, but do you really want that?
As a developer you have to switch your mindset from node 18 and php 8.0 to node 20 and php 8.4 and back. Those little difference that trip you up are tiresome.

My main problem with Forge is that it runs the deployment on the server instead of using build instances that are discarded after a deploy.
And that is why people use NVM if they need to support multiple node versions.
Forge for me is old school deploying. Most git services have better ways of doing deployments nowadays.