Homebrew won't install files outside its prefix and you can place a Homebrew installation wherever you like. Homebrew installs packages to their own directory and then symlinks their files into /usr/local. Get the latest version of the Java Runtime Environment (JRE) for Linux.
If you get a bunch of checkPermissions warnings, you should run the command as the superuser like this: sudo npm i -g npm You now have the latest version installed. Update to the latest version using npm i -g npm. If you do have Node.js installed, it will output the version. npm calculates the dependencies and installs the latest available version of those as well.