{"id":1374,"date":"2023-04-04T18:50:40","date_gmt":"2023-04-04T17:50:40","guid":{"rendered":"https:\/\/editjournal.redakt.eu\/faxmodem\/?p=1374"},"modified":"2023-04-04T18:50:40","modified_gmt":"2023-04-04T17:50:40","slug":"nvm-node-initd-cron-path","status":"publish","type":"post","link":"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/development\/nvm-node-initd-cron-path\/","title":{"rendered":"Add nvm-managed node to $PATH in init.d or crontab"},"content":{"rendered":"<p>When I was using <code>node<\/code> installed via <code>apt-get<\/code>, a simple <code>NODE=$(which node)<\/code> was enough.<\/p>\n<p>However, once I switched to the <code>nvm<\/code>-based node, it was no longer installed in one of the <code>$PATH<\/code> locations where the system is looking. So the correct path had to be added manually.<\/p>\n<p>One option is to hardcode whatever the current <code>node<\/code> path is, but that means the script will stop working as soon as <code>nvm<\/code> switches to a different node version.<\/p>\n<p>Here's how I solved it:<\/p>\n<pre><code>. \/root\/.nvm\/nvm.sh\nNODE_VERSION=`nvm current`\nPATH=\/usr\/bin:\/usr\/local\/bin:\/usr\/local\/sbin:\/sbin:\/bin:\/usr\/sbin:\/root\/.nvm\/versions\/node\/$NODE_VERSION\/bin\nNODE=$(which node)<\/code><\/pre>\n<p>First, we <em>source<\/em> (the <code>.<\/code> command) the nvm environment, which makes the <code>nvm<\/code> command available.<\/p>\n<p>Then we use the <code>nvm<\/code> to tell us the currently selected node version.<\/p>\n<p>Then we add the folder where that version lives to <code>$PATH<\/code><\/p>\n<p>Lastly, we call <code>which node<\/code> as usual.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I was using node installed via apt-get, a simple NODE=$(which node) was enough. However, once I switched to the nvm-based node, it was no longer installed in one of the $PATH locations where the system is looking. So the correct path had to be added manually. One option is to hardcode whatever the current&hellip; <a class=\"more-link\" href=\"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/development\/nvm-node-initd-cron-path\/\">Continue reading <span class=\"screen-reader-text\">Add nvm-managed node to $PATH in init.d or crontab<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[706],"tags":[775,769],"class_list":["post-1374","post","type-post","status-publish","format-standard","hentry","category-development","tag-debian","tag-node-js","entry"],"_links":{"self":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/comments?post=1374"}],"version-history":[{"count":1,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1374\/revisions"}],"predecessor-version":[{"id":1376,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1374\/revisions\/1376"}],"wp:attachment":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/media?parent=1374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/categories?post=1374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/tags?post=1374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}