How to install yarn from source?

6.9k views Asked by At

I am trying to install the yarn package manager from source onto my Ubuntu machine.

1) Download yarn tarball from Github Release page

YARN_VERSION=0.17.1
https://github.com/yarnpkg/yarn/releases/download/v${YARN_VERSION}/yarn-v${YARN_VERSION}.tar.gz

2) Extract gzipped tar

tar -xzf yarn-v${YARN_VERSION}.tar.gz

3) Use it

cd ./dist/bin/yarn --version
>> 0.17.10

So far so good.

GOAL: But what is the recommended way to make the yarn executable accessible through /usr/local/bin/yarn --version?

It seems I need to create a symlink. In that case where is the best place to extract the tarball? Is it /usr/local/lib/yarn? How do I create the symlink?

4

There are 4 answers

0
apeman On BEST ANSWER

For anyone wanting to build from the bleeding edge, I did the following:

cd /my/working/directory
git clone https://github.com/yarnpkg/yarn.git
cd yarn
npm install
gulp build

Then do as z.ky suggests and export PATH=$PATH:/my/working/directory/yarn/bin

1
zoecarver On

You should probably install it in the /opt directory like it says in the documentation.



    cd /opt
    wget https://yarnpkg.com/latest.tar.gz
    tar zvxf latest.tar.gz
    # Yarn is now in /opt/yarn-[version]/

Then you can export the path like so: export PATH="$PATH:yarn global bin"

However if you are running ubuntu you could just use apt-get or the nightly builds.

0
user3024238 On

From above comment, after build reference working directory, needs to be in opposite order otherwise env will pick whatever is out of date if already installed: " For anyone wanting to build from the bleeding edge, I did the following: cd /my/working/directory git clone https://github.com/yarnpkg/yarn.git cd yarn npm install gulp build Then do as z.ky suggests and export PATH=$PATH:/my/working/directory/yarn/bin"

Needs to be PATH=/my/working/directory/yarn/bin:$PATH

0
Villager On

This is what I did on macOS, could you try to adapt it to Ubuntu? Hopefully the commands are close enough/the same.

  1. Add the equivalent of this for Ubuntu to your ~/.profile file (for me it was my ~/.bash_profile file):

    export PATH="$PATH:/opt/yarn-v0.23.2/bin"

  2. Then in the terminal, run source ~/.bash_profile.

  3. Run yarn --version to check that it works - you should be able to run this from anywhere now.

I apologise if this isn't 100% correct for you as I can't test it on Ubuntu, but that's how I got it working on macOS.