LoginSignup
4
1

More than 5 years have passed since last update.

特定のバージョンの Yarn をインストールしたい場合の方法(Ubuntu)

Posted at

前提

  • 特定バージョンの Yarn を Docker 環境内にインストールしたい場合の方法です。

環境

  • Docker Community Edition Version 18.06.1-ce-mac73 (26764)

TL;DR

Dockerfile に以下のように書けばOKです。

Dockerfile
RUN wget https://github.com/yarnpkg/yarn/releases/download/vX.X.X/yarn_X.X.X_all.deb \
    && dpkg -i yarn_X.X.X_all.deb

詳細

公式ドキュメント通りにやると、以下のような形になるかと思います。ただこれだと、常の最新の Stable のバージョンをインストールしようとします。つまり、 docker-compose build を実行するたびに Yarn のバージョンが変わる可能性があります。

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
    && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
    && apt-get update \
    && apt-get install -y yarn

大きいプロジェクトとかだと、バージョンが変わることによって既存コードの挙動も変わるのを避けたいところです。そこで、冒頭のように特定のバージョンを直接取得してインストールする方法をとります。GitHub に各バージョンのパッケージが置いてあるので、インストールしたいバージョンのものを参照してください。

https://github.com/yarnpkg/yarn/releases/tag/v1.10.1
https://github.com/yarnpkg/yarn/releases/tag/v1.9.4
https://github.com/yarnpkg/yarn/releases/tag/v1.8.0
https://github.com/yarnpkg/yarn/releases/tag/v1.7.0
etc...

参考文献

https://stackoverflow.com/questions/46722817/how-to-install-particular-yarn-version-in-ubuntu
https://yarnpkg.com/en/docs/install#debian-stable

4
1
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
1