Reputation: 191
I installed node with nvm it works fine, but every new session i need to do source $HOME/nvm/nvm.sh
to get node active
How can I do to be active on boot so there is no need to type source $HOME/nvm/nvm.sh
in every sssh session
I try to add this command source $HOME/nvm/nvm.sh
to /etc/rc.local
but I get the following error
> /etc/init.d/node_start.sh: 13: root/nvm/nvm.sh: Bad substitution
> /etc/init.d/node_start.sh: 78: root/nvm/nvm.sh: [[: not found
> /etc/init.d/node_start.sh: 78: root/nvm/nvm.sh: [[: not found
> /etc/init.d/node_start.sh: 129: root/nvm/nvm.sh: [[: not found
> /etc/rc.local: 14: /etc/rc.local: source: not found
But if i done that command on shell works normally
Any help is welcome
Regards
Upvotes: 2
Views: 1763
Reputation: 361
You should add the line below to the end of ~/.bashrc file:
[[ -s /home/$USER/.nvm/nvm.sh ]] && . /home/$USER/.nvm/nvm.sh
Upvotes: 1
Reputation: 18998
I expect your init script starts with #!/bin/sh
when it needs to start with #!/bin/bash
. Of course, there may be many good reasons not to write init scripts in Bash...
Upvotes: 0
Reputation: 146154
The init script is running as root, not your user. If you want to source your own nvm.sh
, you shouldn't use $HOME
, but rather just use the absolute path like /home/vitor/nvm/nvm.sh
. Also the init script is probably running under dash
so you should not use the [[
construct. Just use [
instead as described in this dash as /bin/sh article
So I went and read the nvm.sh source code from https://github.com/creationix/nvm/blob/master/nvm.sh
I don't think that is compatible with dash. So I suggest you leave nvm.sh elsewhere in the filesystem and in your init script just do
exec /bin/bash /root/nvm/nvm.sh
Starting node_start.sh
with #!/bin/bash
may also be sufficient.
You may also want to subscribe to issue 168 on github for nvm where others hit this error.
Upvotes: 0