1. Install yarn on your system. For Debian/Ubuntu Linux:
$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn
2. To add any library, for example jquery, to Ruby on Rails 5.1 application with yarn(from npm) type in terminal:
$ yarn add jquery