Skip to content

Instantly share code, notes, and snippets.

@S1SYPHOS
Created February 12, 2018 20:12
Show Gist options
  • Save S1SYPHOS/665e2455ce23ba3c1a5500056c465d19 to your computer and use it in GitHub Desktop.
Save S1SYPHOS/665e2455ce23ba3c1a5500056c465d19 to your computer and use it in GitHub Desktop.
Installing yarn locally w/o sudo
#!/bin/bash
# https://hackernoon.com/how-to-use-yarn-in-a-project-without-installing-yarn-f946815ddb4e
# Choose which version of yarn you want to use
EXPECTED_YARN_VERSION="0.16.1"
function install_yarn {
mkdir -p .yarn
DOWNLOAD_URL="https://github.com/yarnpkg/yarn/releases/download/v$EXPECTED_YARN_VERSION/yarn-v$EXPECTED_YARN_VERSION.tar.gz"
echo "Downloading from $DOWNLOAD_URL"
curl -fL $DOWNLOAD_URL > .yarn/yarn.tar.gz
tar zxf .yarn/yarn.tar.gz --strip-components=1 -C .yarn
}
if [ -f .yarn/bin/yarn ]; then
YARN_VERSION=$(node -e 'const fs = require("fs"); console.log(JSON.parse(fs.readFileSync(".yarn/package.json")).version);')
if [ "$YARN_VERSION" != "$EXPECTED_YARN_VERSION" ]; then
echo "The yarn version is $YARN_VERSION, expected $EXPECTED_YARN_VERSION. Re-downloading"
rm -rf .yarn
install_yarn
fi
else
echo "The file .yarn/bin/yarn does not exist, installing yarn".
install_yarn
fi
./.yarn/bin/yarn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment