現象
Ruby on Railsで本番環境(production)でscss(css)が
反映されないので$ rake assets:precompile RAILS_ENV=production
しようと思ったらyarn入れろって怒られた。
[ec2-user@ip-xxx-xx-xxx-xxx hogehoge]$ rake assets:precompile RAILS_ENV=production
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
$ npm install yarn -g
したらまた怒られた。
[ec2-user@ip-xxx-xx-xxx-xxx hogehoge]$ npm install yarn -g
npm WARN checkPermissions Missing write access to /usr/lib/node_modules
npm ERR! path /usr/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/lib/node_modules' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ec2-user/.npm/_logs/2019-03-17T00_34_58_378Z-debug.log
解決法
sudoしましょう。。
[ec2-user@ip-xxx-xx-xx-xx hogehoge]$ sudo npm install yarn -g
/usr/bin/yarn -> /usr/lib/node_modules/yarn/bin/yarn.js
/usr/bin/yarnpkg -> /usr/lib/node_modules/yarn/bin/yarn.js
+ yarn@1.13.0
added 1 package in 0.486s
結果
幸せな世界が訪れました。
めでたしめでたし。
[ec2-user@ip-xxx-xx-xx-xx hogehoge]$ rake assets:precompile RAILS_ENV=production
yarn install v1.13.0
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.13s.