Node installed using apt-get is not exported to PATH and unable to access though /usr/bin/npm

I wrote an deploy script in node to deploy my java fatJar compiled using gradle to an serverless service platform.
My main image selected is java, so I have to either create an custom image or apt-get install nodejs at build time, since I’m not familiar to docker so I’ve choice apt-get install solution. But I’m unable to run npm or node command, it keeps failing with message: npm: No such file or directory, even if I try to access it directly though /usr/bin/npm, it still isn’t working and system is unable to find npm executable… Can anyone help…? orz

My circle-ci config file:

version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/openjdk:8-jdk

    working_directory: ~/repo

    environment:
      JVM_OPTS: -Xmx1000m
      TERM: dumb

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "build.gradle" }}-{{ checksum "deploy/package.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: gradle dependencies

      - run: sudo apt-get install nodejs

      - run:
          command: /usr/bin/npm i
          working_directory: deploy

      - save_cache:
          paths:
            - ~/.gradle
            - ~/deploy/node_modules
          key: v1-dependencies-{{ checksum "build.gradle" }}

      - run: gradle fatJar

      - run:
          command: npm run run
          working_directory: deploy

fixed… sorry…

1 Like

can anyone help :frowning:

(Please don’t beg - this is a rather quiet forum, especially on Sundays. Thank you for fixing the formatting!)

The behaviour you describe is odd - the file should exist. Are you sure that /usr/bin/npm is the file that cannot be found? I wonder if that is running but it cannot find another file.

You could also try making sure it can run, e.g. by doing chmod +x /usr/bin/npm on it beforehand. Or maybe run it using sh /usr/bin/npm.

Finally, add a step ls -la /usr/bin/n* in case NPM is not installed. I assume it would come with Node, but perhaps it needs to be installed separately for this repo?

1 Like

I recommend running an SSH Job https://circleci.com/docs/2.0/ssh-access-jobs/ and looking to see where the npm is living. It’s a lot more fun then running job after job with different commands.