Npm commands not work in SSH

I really can’t understand why on my machine via SSH I can execute npm commands and in deploy pipeline is not work? Wtf

Starting deploy
Already up to date.
v16.7.0
7.20.3
Deploy end

Result in CircleCI

Starting deploy
Already up to date.
deploy.sh: line 6: node: command not found
deploy.sh: line 7: npm: command not found
Deploy end
version: 2.1

# Define the jobs we want to run for this project
jobs:
  pull-and-build:
    docker:
      - image: arvindr226/alpine-ssh
    steps:
      - checkout
      - run: ssh -o StrictHostKeyChecking=no ubuntu@xx.xx.xx.xx "cd ~/apps/clm/core; sudo bash deploy.sh"

# Orchestrate our job run sequence
workflows:
  version: 2
  build-project:
    jobs:
      - pull-and-build:
          filters:
            branches:
              only:
                - Desenvolvimento

Thanks a lot to anyone who helps I really don’t understand what’s going on I’ve tried looking for everything…

You are going to have to check how the system you are accessing is set up in terms of SSH - while your output shows that the deploy.sh script does get executed, it also indicates that you do not have all the env variables set that you expect - things like PATH are likely to be missing.

As I do not know your environment or the script you are running I can not be certain, but by the time you have started a session via SSH and then also created a new shell via sudo your env is not going to be what you expect.

Hi @rit1010, ty for reply is my script and system info.

#!/bin/bash

echo "Starting deploy"
cd ~/apps/clm/core
git pull

node -v
npm -v
echo "Deploy end"
    description: Computer
    product: t3.micro
    vendor: Amazon EC2
    serial: ec256d83-e231-014e-613d-3d5859bb9ba5
    width: 64 bits
    capabilities: smbios-2.7 dmi-2.7 smp vsyscall32
    configuration: uuid=ec256d83-e231-014e-613d-3d5859bb9ba5
  *-core
       description: Motherboard
       vendor: Amazon EC2
       physical id: 0
     *-firmware
          description: BIOS
          vendor: Amazon EC2
          physical id: 0
          version: 1.0
          date: 10/16/2017
          size: 64KiB
          capacity: 64KiB
          capabilities: pci edd acpi virtualmachine
     *-cpu
          description: CPU
          product: Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
          vendor: Intel Corp.
          physical id: 4
          bus info: cpu@0
          version: 6.85.7
          slot: CPU 0
          size: 2500MHz
          capacity: 3500MHz
          width: 64 bits
          clock: 100MHz
          capabilities: lm fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp x86-64 constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves ida arat pku ospke
          configuration: cores=1 enabledcores=1 microcode=83898890 threads=2
        *-cache:0
             description: L1 cache
             physical id: 5
             slot: L1-Cache
             size: 1536KiB
             capacity: 1536KiB
             capabilities: synchronous internal write-back instruction
             configuration: level=1
        *-cache:1
             description: L2 cache
             physical id: 6
             slot: L2-Cache
             size: 24MiB
             capacity: 24MiB
             capabilities: synchronous internal varies unified
             configuration: level=2
        *-cache:2
             description: L3 cache
             physical id: 7
             slot: L3-Cache
             size: 35MiB
             capacity: 35MiB
             capabilities: synchronous internal varies unified
             configuration: level=3
     *-memory
          description: System Memory
          physical id: 8
          slot: System board or motherboard
          size: 1GiB
          capacity: 1GiB
        *-bank
             description: DIMM DDR4 Static column Pseudo-static Synchronous Window DRAM 2933 MHz (0.3 ns)
             physical id: 0
             size: 1GiB
             width: 64 bits
             clock: 2933MHz (0.3ns)
     *-pci
          description: Host bridge
          product: 440FX - 82441FX PMC [Natoma]
          vendor: Intel Corporation
          physical id: 100
          bus info: pci@0000:00:00.0
          version: 00
          width: 32 bits
          clock: 33MHz
        *-isa
             description: ISA bridge
             product: 82371SB PIIX3 ISA [Natoma/Triton II]
             vendor: Intel Corporation
             physical id: 1
             bus info: pci@0000:00:01.0
             version: 00
             width: 32 bits
             clock: 33MHz
             capabilities: isa
             configuration: latency=0
           *-pnp00:00
                product: PnP device PNP0b00
                physical id: 0
                capabilities: pnp
                configuration: driver=rtc_cmos
           *-pnp00:01
                product: PnP device PNP0303
                physical id: 1
                capabilities: pnp
                configuration: driver=i8042 kbd
           *-pnp00:02
                product: PnP device PNP0f13
                physical id: 2
                capabilities: pnp
                configuration: driver=i8042 aux
           *-pnp00:03
                product: PnP device PNP0400
                physical id: 3
                capabilities: pnp
           *-pnp00:04
                product: PnP device PNP0501
                physical id: 4
                capabilities: pnp
                configuration: driver=serial
        *-generic UNCLAIMED
             description: Non-VGA unclassified device
             product: 82371AB/EB/MB PIIX4 ACPI
             vendor: Intel Corporation
             physical id: 1.3
             bus info: pci@0000:00:01.3
             version: 08
             width: 32 bits
             clock: 33MHz
             configuration: latency=0
        *-display UNCLAIMED
             description: VGA compatible controller
             product: Amazon.com, Inc.
             vendor: Amazon.com, Inc.
             physical id: 3
             bus info: pci@0000:00:03.0
             version: 00
             width: 32 bits
             clock: 33MHz
             capabilities: vga_controller
             configuration: latency=0
             resources: memory:fe400000-fe7fffff memory:c0000-dffff
        *-nvme
             description: NVMe device
             product: Amazon Elastic Block Store
             vendor: Amazon.com, Inc.
             physical id: 4
             bus info: pci@0000:00:04.0
             logical name: /dev/nvme0
             version: 1.0
             serial: vol08a60edf06fab1ca9
             width: 32 bits
             clock: 33MHz
             capabilities: nvme pciexpress msix nvm_express bus_master cap_list
             configuration: driver=nvme latency=0 nqn=nqn.2014.08.org.nvmexpress:1d0f1d0fvol08a60edf06fab1ca9Amazon Elastic Block Store state=live
             resources: irq:11 memory:febf0000-febf3fff
           *-namespace:0
                description: NVMe disk
                physical id: 0
                logical name: hwmon0
           *-namespace:1
                description: NVMe disk
                physical id: 2
                logical name: /dev/ng0n1
           *-namespace:2
                description: NVMe disk
                physical id: 1
                bus info: nvme@0:1
                logical name: /dev/nvme0n1
                size: 8GiB (8589MB)
                capabilities: gpt-1.00 partitioned partitioned:gpt
                configuration: guid=ca87dd15-e59d-45a5-93ea-0fae9b47c00e logicalsectorsize=512 sectorsize=512 wwid=nvme.1d0f-766f6c3038613630656466303666616231636139-416d617a6f6e20456c617374696320426c6f636b2053746f7265-00000001
              *-volume:0
                   description: EXT4 volume
                   vendor: Linux
                   physical id: 1
                   bus info: nvme@0:1,1
                   logical name: /dev/nvme0n1p1
                   logical name: /
                   version: 1.0
                   serial: e7879b8a-f914-4210-998a-d47604682e59
                   size: 8080MiB
                   capacity: 8080MiB
                   capabilities: journaled extended_attributes large_files huge_files dir_nlink recover 64bit extents ext4 ext2 initialized
                   configuration: created=2022-04-21 14:09:16 filesystem=ext4 label=cloudimg-rootfs lastmountpoint=/ modified=2022-12-07 14:16:45 mount.fstype=ext4 mount.options=rw,relatime,discard,errors=remount-ro mounted=2022-12-07 14:53:54 state=mounted
              *-volume:1
                   description: BIOS Boot partition
                   vendor: EFI
                   physical id: e
                   bus info: nvme@0:1,14
                   logical name: /dev/nvme0n1p14
                   serial: 1c219615-9048-4b4c-81a7-a6e32e5fc6a6
                   capacity: 4095KiB
                   capabilities: nofs
              *-volume:2
                   description: Windows FAT volume
                   vendor: mkfs.fat
                   physical id: f
                   bus info: nvme@0:1,15
                   logical name: /dev/nvme0n1p15
                   logical name: /boot/efi
                   version: FAT32
                   serial: 594c-4810
                   size: 105MiB
                   capacity: 105MiB
                   capabilities: boot fat initialized
                   configuration: FATs=2 filesystem=fat label=UEFI mount.fstype=vfat mount.options=rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro state=mounted
        *-network
             description: Ethernet interface
             product: Elastic Network Adapter (ENA)
             vendor: Amazon.com, Inc.
             physical id: 5
             bus info: pci@0000:00:05.0
             logical name: eth0
             version: 00
             serial: 02:a3:3e:b3:60:88
             width: 32 bits
             clock: 33MHz
             capabilities: pciexpress msix bus_master cap_list ethernet physical
             configuration: broadcast=yes driver=ena driverversion=5.15.0-1026-aws ip=172.31.11.211 latency=0 link=yes multicast=yes
             resources: irq:0 memory:febf4000-febf7fff

The issue looks like it is coming down to how you have installed node and npm on the system you remote into.

If you are able to execute the script when you open up an SSH terminal session, but the same script does not complete when you use ssh to execute a remote command you need to look at what is different between the 2.

When you operate from within a terminal do you run “sudo bash deploy.sh” or just “./deploy.sh”?

I’ll be honest, I’ve reach the limit of my understanding here - so while I can see a possible difference between the 2 ways you are trying to execute the script I do not know Linux well enough to say what maybe happening.

@rit1010 Yes the problem was in the PATH thanks for clarify the ideas!

ssh -o StrictHostKeyChecking=no xxx@xx.xxx.xx.xx "source ~/.nvm/nvm.sh; cd ~/apps/xxx/xxx; git pull; npm install; pm2 restart core client"
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.