I'm looking for a simple bash script that can install NVM (Node Version Manager) along with the latest LTS version of Node.js on Ubuntu 22.04. I usually run the following commands just fine in an interactive shell, but I can't seem to get it to work within a bash script. Here's what I normally use: `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash && source ~/.bashrc && nvm install --lts`. Can anyone help me with this?
3 Answers
You might want to try using `asdf`. It's a great tool for managing installations like this. The newer version is a single binary and simplifies managing multiple developer tools, including Node.js.
It sounds like you’re trying to simplify things with a script. Just remember, since `nvm` is a bash script itself, make sure you have the `#!/bin/bash` shebang at the top of your script. Otherwise, it won’t run properly. What’s going wrong specifically when you run your dependencies script?
Have you checked if your `.bashrc` file sources NVM after installation? Sometimes, you need to manually add the NVM source line if it’s missing, or ensure your script is being run in a context where `.bashrc` is loaded.
I’m actually trying to automate the installation of a Python project, including its dependencies, and I’ve had no issue except for NVM. It seems that after installing NVM, I can’t access it when running Python scripts in my bash script. I'm getting a `command not found` error. I've tried sourcing `~/.bashrc` again, but no luck.