0

I installed the yarn by nvm.

root@server:~# which yarn
/root/.nvm/versions/node/v19.0.0/bin/yarn

It works when I login the machine and use yarn in terminal.

root@server:~# yarn -v
1.22.19

But once I try to run yarn in deployer task,

task('deploy:yarn', function () {
    run('cd {{release_path}} && yarn install', ['timeout' => 600]);
});

The command "cd /var/www/my-web-project/releases/1 && yarn install" failed.
Exit Code: 127 (Command not found)
Host Name: example.com
bash: line 1: yarn: command not found

It will throw out error: yarn: command not found


I try to run the yarn in a shell bash via a deployer task

task('deploy:upload-front-end-shell', function () {
    upload('build-front-end.sh', '{{release_path}}/build-front-end.sh');
});

build-front-end.sh

#!/bin/bash

yarn && yarn build

or

alias yarn=$(which yarn)

yarn && yarn build

or

yarn_path=$(which yarn)

$yarn_path && $yarn_path build

None of those shell works via deployer task, but works when I login the machine and run the shell manually.


How can I config my ubuntu20.04 to make yarn works in deployer task?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
DengSihan
  • 2,119
  • 1
  • 13
  • 40

1 Answers1

0

since yarn is installed in /root/.nvm/versions/node/v19.0.0/bin/yarn instead of /usr/bin or /usr/local/bin, so it can't not be found by shell.

just create a soft-link can solve this:

ln -s /root/.nvm/versions/node/v19.0.0/bin/yarn /usr/local/bin/yarn
chomd +x /usr/local/bin/yarn

# also for the node
ln -s /root/.nvm/versions/node/v19.0.0/bin/node /usr/local/bin/node
chomd +x /usr/local/bin/node
DengSihan
  • 2,119
  • 1
  • 13
  • 40