Composer (recommended) If you would like to install the select2 library with composer, you probably used the drupal composer template to set up your project. It's recommended to use asset-packagist to install JavaScript libraries. So you will need to add the following to your composer.json file into the repositories section:
{
"type": "composer",
"url": "https://asset-packagist.org"
}
It's also needed to extend the 'installer-path' section:
"web/libraries/{$name}": [
"type:drupal-library",
"type:bower-asset",
"type:npm-asset"
],
And add a new 'installer-types' section next to the 'installer-path' in the 'extra' section:
"installer-types": [
"bower-asset",
"npm-asset"
],
Be mindful of comma's!
After this you can install the library with composer require oomphinc/composer-installers-extender npm-asset/select2
and the library will be downloaded into the libraries folder.
Expanded example