Ubuntu – Apt-get does not recognize node software installed via nvm

aptnodejspackage-management

I'm trying to install a .deb package however it requires several dependencies such as nodejs, nodejs-underscore, but all of those are already installed via nvm and are available.

Is there anyway I can have apt-get recognize packages installed via nvm so that they don't clash? I know that apt-get is system-wide whereas nvm works at local user-space so this might need some hacking.

Best Answer

The simplest approach, whenever possible is to only use either nvm or .deb packages. This will probably save you a lot of headaches in the long run, so look into that first. It seems like nearly anything node-related that is provided by a .deb package could be installed via nvm instead.

If that really isn't possible, however, you may be able to create "dummy" .deb packages using equivs-control and equivs-build to tell apt that you have the dependencies installed. Note that this could potentially confuse apt if you get things wrong. Also, even if you uninstall nvm packages, apt will still think you have the substitutes you've defined in the dummy packages until you uninstall the dummy packages themselves.

First, install "equivs" so we can build the dummy packages:

sudo apt-get install equivs

Create a control file that describes the dummy package:

cd ~
equivs-control nodejs-dummy

Edit this control file:

nano nodejs-dummy

Un-comment and change lines in the control file as desired. In particular set the "Provides:" line to list the packages that you've substituted using nvm. For example:

Package: nodejs-dummy
Version: (version slightly higher than what the apt package actually provides)
Maintainer: Your Name <yourname@example.com>
Provides: nodejs
Architecture: all
Description: Something that will remind you what this does ;)

Build the package:

equivs-build nodejs-dummy

Finally, install it:

sudo dpkg -i nodejs-dummy_use_the_actual_filename.deb

Rinse and repeat for whatever packages you've substituted using nvm. If a package depends on a specific version of another package you've replaced with nvm, you may need to use that exact version number it depends on. I'm not sure what issues might arise from do so, however, and you'll likely need to keep rebuilding your dummy packages whenever the OS packages change versions.

Related Question