Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NVM not found in AWS CI-CD Pipeline

I am new to create a pipeline in aws. I want to create a ci-cd pipeline for my nuxt project. I create a yml file in which I want to install nvm and then install node version 12.18.3

The problem is I am getting the nvm not found error.

Can you please check and let me know if there is any error in my yml file:

version: 0.2
phases:
  install:
   commands:
     - echo Installing nvm...
     - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
     - export NVM_DIR="$HOME/.nvm"
     - '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"'
     - '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"'
  pre_build:
    commands:
      #install dependencies
      - echo Installing node...
      - nvm install 12.18.3
      - echo Installing npm...
      - npm install
  build:
    commands:
      #build
      - echo building...
      - npm run generate
artifacts:
  files:
    - '**/*'
 base-directory: dist
cache:
  paths:
    - node_modules/**/*

Thank you.

like image 823
Ragu Avatar asked Dec 06 '25 04:12

Ragu


1 Answers

You don't actually need to use nvm to install specific node.js version on AWS CodeBuild.

You can use runtime-versions option which would install some version, but you don't have much control over this.

phases:
  install:
    runtime-versions:
      nodejs: 12.x

But AWS standard 5 image comes with n preinstalled (haven't checked 4 but it should be there as well), so you can use it like:

phases:
  install:
    commands:
      - n 12.18.3

and it would install that version same as nvm.

like image 165
Karolis Avatar answered Dec 07 '25 18:12

Karolis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!