Currently Ploi installs node/npm LTS version.
We have some projects that need an older version of node/npm to build assets, so it would be very helpful for us to have a node version manager installed by Ploi so that we can switch node version in the deploy script.
For example nvm or n.
They both have the option to set a dot file in your repo and it will set the correct node version from that file.
github.com/nvm-sh/nvm/blob/master/README.md#nvmrc
github.com/tj/n#specifying-node-versions
Once a user added the file to their project they will only need to add nvm use or n auto to their project.
Very much needed. To be Honest I have a legacy project that is vey critical and running on Node 10.2. We started it in 2018 on LaravelForge. One of the reasons for not migrating it to Ploi yet is that I am too lazy to install Old node version manually.
@Dennis just revisiting this. I've also didn't find nvm on the server anywhere. Is this correctly working?
I'm having the same issue. There seems to be no NVM after installing it through Ploi.
looks like nvm gets installed in the home dir of the root user
/root/.nvm
There are multiple issues to solve here, for example:
- using nvm on other users then Ploi
- pm2 is still run on "system node"
- What about globally installed npm packages.
I think i have a dirty workaround for the first issue that requires some, keep in mind this is not production ready, use at your own risk.
Install nvm via the ploi user
mkdir /usr/local/nvm
curl https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | NVM_DIR=/usr/local/nvm bash
The dirty path
that should be changed with group privileges for example but did not get this to work yet. This makes it so every user can install and use nvm cache.
mkdir /usr/local/nvm/.cache && chmod -R 777 /usr/local/nvm/.cache
mkdir /usr/local/nvm/versions && chmod -R 777 /usr/local/nvm/versions
mkdir /usr/local/nvm/alias && chmod -R 777 /usr/local/nvm/alias
Add nvm init to profiles
echo 'export NVM_DIR="/usr/local/nvm"' | sudo tee -a /etc/profile.d/nvm.sh
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | sudo tee -a /etc/profile.d/nvm.sh
According to https://stackoverflow.com/questions/11542846/nvm-node-js-recommended-install-for-all-users#comment58129097_19040346
... you should NOT EVER install
nvmas root.nvmis per-user. If you want to share node across users, nvm is the wrong tool to use.
Did you get it to work in a deploy script? I always get nvm: command not found.
Tried sourcing the .bashrc file manually in the deploy process and a few other shenanigans, but no luck..
Thank you for your time and comment, unfortunately this does not work for me. Its not doing anything with nvm use and it still uses the wrong / default version.
Sadly it doesn't work for you. can't help you out any further since I can't look into your setup.
All I can advise is making sure you've logged into the server via (as the user your site is attached to). Install nvm for that user (so you end up with a folder /home/{user}/.nvm). After installing run source ~/.bashrc to load nvm, and run nvm install v... to install the required version.
I forgot that nvm use doesn't automatically install but its the other way around. By calling nvm install instead of use its installing and also using the correct version and it's working now. Thank you very much :)
Found out today this still is an issue, any chance this will be resolved in the near future?