yarn self-update should update using the same installation method originally used

Created on 17 Oct 2016  ·  64Comments  ·  Source: yarnpkg/yarn

Do you want to request a _feature_ or report a _bug_?
Feature

What is the current behavior?
yarn self-update always downloads a tarball.

What is the expected behavior?
yarn self-update should update using the same installation method used by the user. For example, if Yarn was installed via the Debian/Ubuntu package, yarn self-update should run sudo apt-get update && sudo apt-get install yarn. On Windows when installed via the installer, it should download https://yarnpkg.com/latest.msi and execute it.

This is closely related to #1138 ("add yarn version check on startup") in that both issues need some way of determining the installation method used by the user.

cat-feature good first issue help wanted high-priority triaged

Most helpful comment

@kristojorg I had the same problem. I (think I) fixed it by doing a bunch of things:

  1. Removing yarn binaries manually:
# remove binaries
rm -f /usr/local/bin/yarnpkg
rm -f /usr/local/bin/yarn

# remove cache
rm -rf ${HOME}/.yarn
  1. If you have the following in your .zshrc or .bash_profile, remove it:
export PATH="$PATH:`yarn global bin`"
  1. Install via curl:
curl -o- -L https://yarnpkg.com/install.sh | bash
  1. Make sure there is the following line in your .zshrc or .bash_profile:
export PATH="$HOME/.yarn/bin:$PATH"

Now if you try to run yarn -v, you should get the latest stable version.

All 64 comments

Do you want to close this since self-update was removed with https://github.com/yarnpkg/yarn/pull/1429?

No, the plan is to reinstate a version of self-update that uses the right
installation method.

Sent from my phone.

On Dec 7, 2016 2:04 AM, "Scott Busche" notifications@github.com wrote:

Do you want to close this since self-update was removed with #1429
https://github.com/yarnpkg/yarn/pull/1429?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/yarnpkg/yarn/issues/1139#issuecomment-265172525, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAFnHdMyShESFRQIiqAJhZEWI_HgajUoks5rFXmNgaJpZM4KYOBW
.

https://yarnpkg.com/en/docs/cli/self-update should probably be removed/updated

If I'm on 0.18.1, how do I update to the next version?

@meta-meta Currently, you need to manually upgrade.

how about yarn global add yarn?

I'm a big fan of Yarn but am a little concerned at how self-update was removed with no deprecation notice, no mention in the release notes, and that it was bundled in with a PR that is largely unrelated and where there was no discussion about removing self-update.

I understand that it is early days for Yarn and that API changes are to be expected but it would be good if there was a process for removing core functionality.

(sorry if this isn't the right place to discuss, but this PR is where the docs link to)

how about yarn global add yarn?

Installing Yarn via Yarn is not a supported use case at the moment, and can cause several issues. We don't recommend it at the moment.

@dancoates - The self-update command never really worked 100% correctly, that PR just removed the remnants of the existing command while adding some framework stuff for the new self-update (which will come in the future, as per this issue)

How can I manually update yarn? Not sure about that one, I used brew on my mac to get it working but not sure what "manual" means here... any tips appreciated.

Upgrade it the same way you upgrade any other app installed using Homebrew.
I assume it has an "upgrade" command.

Sent from my phone.

On Jan 26, 2017 9:11 AM, "Cato" notifications@github.com wrote:

How can I manually update yarn? Not sure about that one, I used brew on my
mac to get it working but not sure what "manual" means here... any tips
appreciated.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/yarnpkg/yarn/issues/1139#issuecomment-275447861, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAFnHSm1RTv0bZMHtPxkWkS01hPl5Rm3ks5rWNPJgaJpZM4KYOBW
.

@CatinhoCR I initially installed yarn using npm, so I did npm uninstall -g yarn and then brew install yarn - And now I've got the latest version. It would also work using the brew upgrade command as @Daniel15 mentioned.

npm update yarn -g

You might install yarn width homebrew.So brew uninstall yarn.And it's not a good choose to install yarn with homebrew when you need to across the wall.Everytime you need to brew update.It's always time out.....

Sadly, npm update yarn -g does not always do the trick. For example, it did not update from v.0.20.3 to v.0.21.3 on my OS/X machine. But the following did work:

npm uninstall yarn -g
npm install yarn -g

npm sometimes has weird issues which is why we don't recommend using it to install Yarn.

@wardbell Simply running install works, too:

npm install yarn -g

No need to uninstall first.

I have tried updating manually through homebrew, but when I type yarn --version it is still showing 19.0. I am now trying to uninstall, but seemingly also cannot do that... yarn --version still shows 19.0 after a brew uninstall yarn. I also tried npm uninstall yarn with no luck either.

Can you tell me what I need to delete in order to have yarn completely uninstalled so I can reinstall with the newer version?

@kristojorg I had the same problem. I (think I) fixed it by doing a bunch of things:

  1. Removing yarn binaries manually:
# remove binaries
rm -f /usr/local/bin/yarnpkg
rm -f /usr/local/bin/yarn

# remove cache
rm -rf ${HOME}/.yarn
  1. If you have the following in your .zshrc or .bash_profile, remove it:
export PATH="$PATH:`yarn global bin`"
  1. Install via curl:
curl -o- -L https://yarnpkg.com/install.sh | bash
  1. Make sure there is the following line in your .zshrc or .bash_profile:
export PATH="$HOME/.yarn/bin:$PATH"

Now if you try to run yarn -v, you should get the latest stable version.

Thank you!

@kristojorg Can you also change 2. to have ${HOME} instead of /Users/adrianmcli

*Just adding this for the benefit of those on Microsoft Windows.
If you originally installed Yarn using Chocolatey (the package manager for Windows), then to update it to the latest release, simply do the following:

  1. Launch open the Windows command shell (cmd.exe) as an administrator.
  2. Run the command: c:>choco upgrade yarn
  3. Run, c:>yarn --version, and confirm that it's been upgraded to the latest version. Voila!

On Ubuntu 16.04, yarn automatically updates via Software & Updates.

I had a similar problem, and the problem wasn't that npm wasn't updating yarn (it was), but that there were apparently two links in my environment:

One for /usr/bin/yarn that was pointing to /usr/lib/node_modules/yarn/bin/yarn.js (this was the most recent version installed by npm)

And one for /usr/local/bin/yarn that was pointing to /usr/local/lib/node_modules/yarn/bin/yarn.js (this was an old version)

I don't know where the /usr/local/bin/yarn link was coming from, but it was the one being used by my shell when I just typed yarn. I removed the link and now all is good.

@M-D-M How did you remove the /usr/local/bin/yarn link if you didn't know where it was coming from?

@skube sudo unlink /usr/local/bin/yarn

@M-D-M Thanks. So I did unlink /usr/local/bin/yarn which seemed to work.
and then in order to update to the latest, ran npm i -g yarn which seemed to just link up again

❯ npm i -g yarn
/usr/local/bin/yarnpkg -> /usr/local/lib/node_modules/yarn/bin/yarn.js
/usr/local/bin/yarn -> /usr/local/lib/node_modules/yarn/bin/yarn.js

And yet I'm still not updated to the latest 0.24.6

❯ yarn -v
yarn install v0.24.5
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 1.51s.

Interestingly enough, when I do sudo npm install --global yarn, the /usr/local/bin links aren't being created, so there's some difference in our environments I can't account for. As for 0.24.5 being the available version, that seems maybe be an npm problem -- 0.24.6 isn't being installed, for some reason.

I can confirm that 0.24.6 is not being installed. I have 0.24.5 and when I run npm outdated -g, npm doesn't recognize there's an update available. I don't know if this is an npm issue or an issue with the yarn package.

I am using nvm to manage my node installations, so I don't really have a choice. I need to use npm to install yarn.

Interestingly, on another machine I was able to...

warning Your current version of Yarn is out of date. The latest version is "0.24.6" while you're on "0.21.3".
info To upgrade, run the following command:
$ curl -o- -L https://yarnpkg.com/install.sh | bash

So I did

❯ curl -o- -L https://yarnpkg.com/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6746    0  6746    0     0  22490      0 --:--:-- --:--:-- --:--:-- 22561
Installing Yarn!
/usr/local/bin/yarn
> Downloading tarball...

> We've added the following to your .zshrc
> If this isn't the profile of your current shell then please add the following to your correct profile:

export PATH="$HOME/.yarn/bin:$PATH"

> Successfully installed Yarn 0.24.6! Please open another terminal where the `yarn` command will now be available.

@octopitus In my case I had to add permissions with sudo yarn add global yarn.

brew upgrade yarn and brew link --overwrite node worked to update yarn on OSX sierra

You mean brew link --overwrite yarn for the second command right?

I believe @localredhead has installed yarn with node. I installed yarn as follows:
brew install yarn --without-node, because I manage node by using nvm.

Probably he is overwriting the link to node, so that he's using the right version instead of the one coming with/from yarn.

It might seem obvious to some, but on Windows mine was installed (I think from the MSI, or from a dev env setup script my company provides) in Program Files (x86). No matter what upgrade method I used yarn version wouldn't budge. I eventually discovered the cause with which yarn which pointed to the offending location. I had to use Windows' "Change or Remove a program" to first to remove it, then simply npm install -g yarn to reinstall at the latest version. Now I can just use npm to control the version, which is much better.

@mikechamberlain This worked for me, thanks!

Latest state: we need to reimplement the self-update command that uses the original installation method.

Working on the reimplementation.

@onurtemizkan It should be relatively straightforward. Feel free to message me if you get stuck :)

We already have information on the command that needs to be ran (as Yarn prints out a notice with the command when the version is outdated), Yarn just needs to actually run it. A slightly different case is on Windows when the installer was used, as we'd have to download the installer then msiexec it.

Sorry to interrupt 😉

Have you considered simply delegating this to npm (assuming of course yarn runs if npm exists in the first place).

» npm update -g yarn

The nice thing is that if it does not work out you can always:

So we tried to get npm to handle the update...

Here are your options:
…

Now, aren't u glad to be using yarn for your other packages!

@smotaal There's a few issues with that:

  • If you installed Yarn via another method, you'll now have two versions of Yarn installed (one via the system package manager, and one via npm)
  • Not everyone has npm installed. Yarn does not require npm installed to run

if your system is Windows and had installed npm ,you can use npm install yarn@latest -g to update to top version.

I can't remember how I set it up on this mac roughly a year ago, I know I was using something other than NPM at one point, but when I lost my thread I simply NPMed and I have no issues other than yarn complaining when I'm fairly behind which reminds me to update and I simply npm update -g yarn and forget about it till next reminder.

From a user's perspective, I think yarn can recommend "supported" and maybe mention "unofficial" where if "unofficial" and it does not "work as intended" please use "supported" to install and here is "recommended" if you need to undo "unofficial"

Honestly, it is important for a package manager to have a clear path for itself to be well-managed.

@onurtemizkan are you still working on this?

Are there any updates?
My current approach is: yarn global add yarn@latest which doesn't seem like ideal way

For those just wanting to update yarn automatically on windows, without having to download the binary, I've been using choco for a while to do that, and it is doing this job flawlessly. It's a cmd line tool to install programs (just like apt-get). You just run choco install yarn, and yarn is installed. To update, the command is choco upgrade yarn.

No sorry, chocolatey is just horrible.

If you don't like Chocolatey, don't use it.

I think it's pretty good though. At work we have a lot of internal
Chocolatey packages for various software packages. Seems to work well.

In any case, this issue is specifically for reimplementing self update in
Yarn. It'll only use Chocolatey if that's what you originally used! If you
used the installer directly, upgrades would also use the installer
directly. So it won't force you to use Chocolatey.

Sent from my phone.

On Fri, Apr 20, 2018, 8:25 AM Benjamin Staneck notifications@github.com
wrote:

No sorry, chocolatey is just horrible.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/yarnpkg/yarn/issues/1139#issuecomment-382869380, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAFnHRZ-MoIxY2rwVGVHWCqXEPQRAlKHks5tqPKggaJpZM4KYOBW
.

Scoop is an alternative to Chocolatey and works a lot like brew.

Yarn just told me my yarn version was out of date and asked me to update to the latest yarn version. However, it’s recommendation - a curl & bash command - makes me a little uncomfortable. Wouldn’t this command be effectively the replacement for the need to curl & pipe to bash to upgrade yarn? Would this command act as yarn’s main & frequent upgrade method?

This is a pretty poor experience for new users:

1) Pull the official and current LTS Docker image (10.12.1) for node, which includes Yarn 1.10.1.
2) yarn import
3) yarn install says the version of yarn is out-of-date and recommends a curl | bash command, which is generally considered a bad idea by sysadmins and devops teams.
4) Find and run yarn self-update at https://yarnpkg.com/en/docs/cli/self-update, which links to this Github issue.
5) Forget which problem with npm made me try yarn in the first place.

It's kinda crazy how this still isn't fixed. After more than a year, I think my solution (here) is still the cleanest there is (even though it's tedious and annoying).

We should collaborate to get a command in place for this! The hard work of the installer is already done, it's a matter of packaging up the replace and run into a yarn command.

still not working?!

I'll summarize my solution above again here:

  1. Remove Yarn manually

    # remove binaries
    rm -f /usr/local/bin/yarnpkg
    rm -f /usr/local/bin/yarn
    
    # remove cache
    rm -rf ${HOME}/.yarn
    

    If you have the following in your .zshrc or .bash_profile, remove it:

    export PATH="$PATH:`yarn global bin`"
    
  2. Install latest Yarn (via curl)

    curl -o- -L https://yarnpkg.com/install.sh | bash
    

    Make sure there is the following line in your .zshrc or .bash_profile:

    export PATH="$HOME/.yarn/bin:$PATH"
    

Finally, run yarn -v to check your new version number.

If anyone wants to work on this... We actually already have code that determines the command that needs to be ran to upgrade Yarn:
https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/install.js#L86-L129

You'd just need to add a "self-upgrade" command that runs the correct command.

@Daniel15 I've submitted a pull request for this, looking forward for some feedback. Thanks.

This works for me:

brew upgrade yarn
npm update yarn -g

Any news on this? npm update yarn -g works in the meantime I suppose.

Any news on this?

@crmpicco For now, you still need to update manually.

It seems that yarn policies set-version [range] was implemented by @arcanis and can grab and set the latest version. Though, the ergonomics of the command don't suggest it installs a new version of Yarn -- it still works.

So, yarn policies set-version nightly will get you on the latest build. PR:
https://github.com/yarnpkg/yarn/pull/6673

I'm not sure what that would mean if you want to uninstall yarn, though. :thinking:

There is an Upgrade Yarn section in the docs: https://yarnpkg.com/en/docs/install

@ilias-t this is not about updating, but rather using the same installation method to update.

This issue is over 2yrs old, seems like you don't care. Just remove the command, it's not working & misleading.

This command doesn't exist so it'll be hard to remove 🙂

As far as I'm concerned, I believe the original intent of this issue is fixed with yarn policies set-version. In case it doesn't work as expected, please feel free to open a new issue.

Was this page helpful?
0 / 5 - 0 ratings