42

Amazon Beanstalk installs node and npm into really obscure places - and I'm not sure they won't change if EB decides to use a newer version of node, which would cause my application to break.

These are the locations for node and npm:

/opt/elasticbeanstalk/node-install/node-v0.8.24-linux-x64/bin/node
/opt/elasticbeanstalk/node-install/node-v0.8.24-linux-x64/bin/npm

I'm worried about the 0.8.24 part changing and I'd rather not grep for things in cron or monit scripts when trying to find something that is normally just /usr/bin/XXX.

how do I get a consistent filepath for these executables? and why does EB do this?

for reference, I tried setting the NodeVersion option in an .ebextensions/app.config, it had no effect on the install location.

2
  • I'm assuming those locations aren't in PATH? Commented Aug 13, 2013 at 16:33
  • 1
    yes, that is correct, they are not Commented Aug 14, 2013 at 8:21

5 Answers 5

63

You can add the most recent node and npm binaries to $PATH with a command like this:

PATH=$PATH:`ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin

I couldn't figure out how to prevent beanstalk commands from resetting the $PATH back again.

If you are so inclined you can probably create a symlink with a command similar to the above and use that as your reference point in cron scripts etc.

Agreed, it is very very annoying.

Sign up to request clarification or add additional context in comments.

2 Comments

Or just use the $NODE_HOME environment variable as suggested in dorianm's answer
sudo ln -sf ls -td /opt/elasticbeanstalk/node-install/node-* | head -1/bin/node /bin/node
31

Following Peter Johnson & Greg Tatum replies I created a symlink to the latest node executable:

container_commands:
  01_node_binary:
    command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node"
  • I find the latest version of the node install binary
  • Out of it I create a symlink in the /bin directory (which is part of the $PATH)

3 Comments

This script will fail next time when the app is deployed
Thanks @h-kippo I updated it so it forcefully creates the symlink if it already exists (if this was the problem)
To clarify, this should go in a file like .ebextensions/nodepath.config, right?
11

We had a similar issue with "node not found", trying to run node in container commands. After running ps aux on the EC2 instance we saw that EB has access to the $NODE_HOME env var:

su -s /bin/sh -c PATH=$PATH:$NODE_HOME/bin $EB_NODE_COMMAND 2>&1 nodejs

This can be used in .ebextensions, e.g.:

container_commands:
  your_node_script:
    command: 'env PATH="$PATH:$NODE_HOME/bin" ./bin/your_node_script'

(thanks to Alan Grow)

3 Comments

This seems more robust than the accepted answer in that it uses the node version setting rather than just picking the most recently installed version (or whatever arbitrary sort order)
command: 'env PATH="$PATH:$NODE_HOME/bin" sh -c 'npm run build' works fine. thanks
This does not look like it works for me, as NODE_HOME seems to not be set :(
3

I created the file /.ebextensions/node.config in my project folder to declare my node version and add symlinks to the /bin folder. More information about the .ebextensions folder can be found here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

option_settings:
  - option_name: NodeVersion
    value: 0.12.2
files:
  "/bin/node" :
    mode: "755755"
    content: "/opt/elasticbeanstalk/node-install/node-v0.12.2-linux-x64/bin/node"
  "/bin/npm" :
    mode: "755755"
    content: "/opt/elasticbeanstalk/node-install/node-v0.12.2-linux-x64/bin/npm"

3 Comments

This does allow me to run npm and node from any path when I've ssh'ed into my eb instance, but for some reason the command will never "take" an argument. For example, npm install results in just listing all the possible options for npm.
That's because these are evaluated as shell scripts, not symlinks. Try mode: "100755" instead.
According to the latest docs you have to start with "120xxx" to create a symlink: docs.aws.amazon.com/elasticbeanstalk/latest/dg/…
1

Amazon Elastic Beanstalk

Grand the access to node command

  1. sudo su
  2. vipw
  3. nodejs:x:496:494::/tmp:/bin/bash (":wq" to save changes)
  4. sudo su nodejs
  5. PATH=$PATH:ls -td /opt/elasticbeanstalk/node-install/node-* | head -1/bin
  6. node -v (enjoy :)

1 Comment

Stack overflow isn't rendering the back ticks, which are required, (see Peter Johnsons answer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.