4
2

More than 3 years have passed since last update.

Ubuntuにインストールしたyarnが実行できない

Posted at

Ubuntuにインストールしたyarnが実行できない

Ubuntu 16.04に最新のyarnをインストールした際、yarnコマンドを実行すると以下のようなエラーが発生しました。

$ yarn -v
/usr/share/yarn/lib/cli.js:46099
  let {
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/share/yarn/bin/yarn.js:24:13)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)

yarnと関係ありそうなものとして、Nodejsがあるので、Nodejsのバージョンを確認します。

$ nodejs -v
v4.2.6

そういえば、レポジトリを更新しない状態でapt install nodejsをすると、古いバージョンがインストールされるようだった気がします。

yarnの公式HPを確認すると、Nodeのバージョンが4.8.0以上となっていました。
いつの間に!
Yarn公式HP

なので、今回はバージョン10系のnodejsがインストールできるように、レポジトリを追加します。
そして、インストール済みのnodejsを削除して、新しいnodejsをインストールします。
コマンドは以下の様になります。

*最新のバージョンをインストールしたい場合は、curlコマンドのurl部分を変更してください。
例) バージョン12系をインストールしたい
-> curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
$ sudo apt remove nodejs
$ sudo apt install nodejs

これで、yarnコマンドが実行できれば、解決です。

$ yarn -v
1.21.1

お疲れさまでした。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2