DEV Community

Christian Sedlmair
Christian Sedlmair

Posted on • Updated on

Setup Node on Debian ..and !Yarn

Overview

Note

Vite needs Node and its included npm and npx.

⚠️ Yarn Since 2.x, by default, deletes the node_modules folder, see Stackoverflow. For Vite it means that it breaks. Finally i decided for npm, removed all yarn and all folders and files it created on my projects.

Production server

remove all Nodes from root level

Login on production server with root user and check that the output is «command not found». If there would be a stale smylink, the -v would also not work but different output

$ node -v
bash: node: command not found
$ npx -v
bash: npx: command not found
$ npm -v
bash: npm: command not found
$ yarn -v
bash: yarn: command not found
Enter fullscreen mode Exit fullscreen mode

Check /bin/, /sbin/, /usr/bin/, /usr/sbin/ for stale symlinks and check for node_modules/ folder in /bin/lib/.

Check sources (/etc/apt/sources.list, /etc/apt/sources.list.d/ for any nodes, and, if, remove them.

Check on user level

Login on the user where your app should run.

NVM is recommended by npm and i am satisfied since years. Just updating Node version did'nt work for me, so i gone the hard way, removed the old, installed it anew and then installed the current Node version.

`$ rm -rf ~/.nvm`
Enter fullscreen mode Exit fullscreen mode

Like on root level, check that no nodes are there.

Install Node

Regarding to GitHub/nvm#installation, perform:

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

Logout, Login, and nvm -v should work.

$ nvm install node
Enter fullscreen mode Exit fullscreen mode

=> node -v, npm -v, npx -v should print out the current versions.

⚠️ Pitfall!

In ~/.bashrc there may be a piece of code like this:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac
Enter fullscreen mode Exit fullscreen mode

If shell is running interactive, which means you are not logged in by username and password (login-shell) the code execution ends there.

nvm needs a code piece like this, i have it also in ~/.bashrc

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
Enter fullscreen mode Exit fullscreen mode

So, make sure that its above the previous mentioned code block. Otherwise, if the app is running, it runs shell as interactive and nvm is not working, while you, by ssh on the server, think its working.

Top comments (0)