10

I am trying to install the aws-cdk and in the terminal and I run the npm install -g aws-cdk. As stated here After npm runs, I get:

/usr/local/Cellar/node/9.8.0/bin/cdk -> /usr/local/Cellar/node/9.8.0/lib/node_modules/aws-cdk/bin/cdk
+ aws-cdk@0.31.0
updated 1 package in 1.636s

If I try to run cdk I get:

zsh: command not found: cdk
T. Gerdy
  • 574
  • 1
  • 7
  • 13
  • 3
    Could it be that `/usr/local/Cellar/node/9.8.0/bin` is not in your PATH? Can you try to run `/usr/local/Cellar/node/9.8.0/bin/cdk` directly? – Elad Ben-Israel May 13 '19 at 21:05
  • 1
    @EladBen-Israel I have similar issue...[here](https://stackoverflow.com/questions/56743700/enoent-error-installing-aws-cdk-node-module) Can you please comment on this? – overexchange Jun 24 '19 at 21:58

5 Answers5

15

Installing as root worked for me: sudo npm install -g aws-cdk

yogender
  • 496
  • 4
  • 7
7

Make sure /usr/local/Cellar/node/9.8.0/bin is in your PATH

Elad Ben-Israel
  • 824
  • 4
  • 6
5

In my case, I added this to the end of my .bash_profile: export PATH=$PATH:$(npm get prefix)/bin. I did that based on information from a different thread.

Michael Behrens
  • 911
  • 10
  • 8
2

If you're using nvm to manage your node versions, make sure that the CDK package is being installed in the same version of node you're currently using or the version you want to use.

The OP noted their CDK was getting installed in node/9.8.0:

  1. Check the current node version running: nvm current.

  2. If you see that the CDK installation location is different than the node version indicated by nvm current, you'll need to switch your node version using: nvm use <node-version-where-cdk-is-installed>

In the OP's case, this would be nvm use 9.8.0.

2

What worked for me in mac was adding to the path the bin directory of globally installed node modules.

  1. Install aws-cdk by: npm install -g aws-cdk
  2. Try to run it cdk
  3. no command found error
  4. make or edit your .zshrc file in your user directory
  5. add line to .zshrc with export PATH=$PATH:/{your_user_path}/.npm-global/bin
  6. execute it source .zshrc
  7. now cdk should work

Pay attention that it is mac based approach.

Maciej Sikora
  • 19,374
  • 4
  • 49
  • 50