I'd like to update a package that I used cargo install to globally install packages, such as rustfmt or racer. I can't find a way to update an installed package without first deleting it (via cargo uninstall) and then running the install command again. Is there an update command?
There is no such command in vanilla cargo (well, there's cargo install but that's for dependencies), but since cargo supports third-party subcommands there is an answer: the cargo-update crate.
Install as usual with
cargo install cargo-update
then use
cargo install-update -a
to update all installed packages, for more usage information and examples see the cargo install-update manpage.
Disclaimer: am author
As of Rust 1.41.0, you can use the following command to update crates to their latest version:
cargo install <crate>
This came from pull request #6798 (Add install-upgrade) and was stabilized in #7560 (Stabilize install-upgrade).
How does it work?
Instead of failing when cargo install detects a package is already installed, it will upgrade if the versions don't match, or do nothing (exit 0) if it is considered "up-to-date".
Forcing an upgrade / re-installation
The following command will always uninstall, download and compile the latest version of the crate - even if there's no newer version available. Under normal circumstances the install-upgrade feature should be preferred as it does save time and bandwidth if there's no new version of the crate.
cargo install --force <crate>
Documentation
Further information can be found in the GitHub issue rust-lang/cargo#6797 and in the official documentation chapter.
A solution I've found is to add the --force flag to the install command. For example cargo install --force clippy. This will effectively re-install the latest version.
Here is a one-liner to update all installed Cargo crates, except those installed from a local folder:
cargo install $(cargo install --list | egrep '^[a-z0-9_-]+ v[0-9.]+:$' | cut -f1 -d' ')
Explanation:
List installed packages
Filter to lines which contain package names and versions, and exclude ones with filesystem paths
Cut those lines to only include the package name
cargo install with the resulting package names
Related
I'm trying to install a Rust crate on my system (Arch Linux) using Cargo. I can search for crates and find what I need, for example:
$ cargo search curl | head -n3
Updating registry `https://github.com/rust-lang/crates.io-index`
curl (0.3.0) Rust bindings to libcurl for making HTTP requests
curl-sys (0.2.0) Native bindings to the libcurl library
When I try to install it, I get the following error:
$ cargo install curl
Updating registry `https://github.com/rust-lang/crates.io-index`
error: specified package has no binaries
What does this mean? Do I have to build it from source first? What's the point of Cargo if it does not install it in the first place?
$ uname -a
Linux 4.6.1-2-ARCH #1 SMP PREEMPT Thu Jun 2 15:46:17 CEST 2016 x86_64 GNU/Linux
$ rustc --version
rustc 1.9.0
$ cargo --version
cargo 0.10.0 (10ddd7d 2016-04-08)
cargo install is used to install binary packages that happen to be distributed through crates.io.
If you want to use a crate as a dependency, add it to your Cargo.toml.
Read the Rust getting started guide and the Cargo getting started guide for further information. In short:
cargo new my_project
cd my_project
echo 'curl = "0.3.0"' >> Cargo.toml
Amusingly, you can install a third-party Cargo subcommand called cargo-edit using cargo install that makes it easier to modify your Cargo.toml file to add and remove dependencies!
cargo install cargo-edit
cargo add curl
cargo rm curl
An important thing to note is that every Cargo project manages and compiles a separate set of dependencies (some background info). Thus it doesn't make sense to install a compiled library. The source code for each version of a library will be cached locally, avoiding downloading it multiple times.
See also:
cargo install <library_name> --library (Cargo issue #2552)
cargo-add documentation (added to Cargo directly in 1.62.0)
I installed Rust on my Ubuntu 16.04 machine through
curl https://sh.rustup.rs -sSf | sh
as can be seen on the Installation Page.
How do I now uninstall Rust?
To uninstall rustc, rustup and cargo from my Ubuntu 16.04 installation, I did:
rustup self uninstall
and it worked.
If you pay attention to the message you get while installing, you will find the command you are looking for:
As for Linux based operating systems, the following command can be used:
rustup self uninstall
this will remove all the Rust Compiler, Tool Chains and Data including rustc and cargo
If you're one window this should wok, but you have to remove C++ build tools manually if you want to remove it as well, though I would never recommend.
You can do this without manually deleting the old rust binaries by uninstalling cargo and then auto-removing its now un-needed dependencies:
sudo apt remove cargo
sudo apt autoremove
I am currently trying to find a way to install the package openjdk8 on a FreeBSD 9.2.
To do that I used :
sudo pkg install openjdk8
It worked without any problem. However, this has also updated the perl package to the version 5.24. We have many scripts that work only with perl 5.16.3 so I would like to keep this version of perl.
I already tried to uninstall the perl 5.24 package and to reinstall perl 5.16.3 and it worked. So I am convinced openjdk doesn't really need to update this package. I already tried to lock the package perl 5.16.3 but openjdk8 refuse to install himself. I have this message :
perl 5.16.3 is locked and may not be modified
The installation ends and my package is not installed. Also, for specific reasons I don't want to use the port method. I absolutely want to use the pkg method.
So my question is this one : Is there a way to complete my installation of openjdk8 and to prohibit perl to update ?
Thanks for your help.
I finally found an answer to my question. By installing my package offline, it installs the minimum of dependencies. It's not a very popular way to install packages on FreeBSD but it works very well.
Just follow this :
sudo pkg install -F openjdk8
This command allow you to just fetch your packages and its dependencies. Once it's done, you have to find the location of the packages you just fetched.
sudo find / -n *.txz -print
For me the result was
/var/cache/pkg/openjdk8-8.112.16_1-1baeb24a94.txz
Then I go to this directory with :
cd /var/cache/pkg
Now you just have to use :
sudo pkg-static add openjdk8
That's all. It will extract the package and the minimum of dependencies.
Probably you are updating other packages and therefore is updating Perl, when installing openjdk8 no other dependencies are fetched also there is no perl dependency in the port Makefile.
This is the output when installing only openjdk8:
# pkg install openjdk8
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (0 conflicting)
The following 1 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
openjdk8: 8.152.16
Number of packages to be installed: 1
The process will require 165 MiB more space.
Indeed you can install the package without having Perl.
What you can do is install openjdk8 and then install the version of Perl that you require, at the end, it should not modify/affect the openjdk8 package.
Also, this could be useful,
pkg install --dry openjdk8
This will check what will be installed.
And in case there is a dependency (let's say you don't have perl) this you could try this:
pkg install --ignore-missing openjdk8
I'd like to update a package that I used cargo install to globally install packages, such as rustfmt or racer. I can't find a way to update an installed package without first deleting it (via cargo uninstall) and then running the install command again. Is there an update command?
There is no such command in vanilla cargo (well, there's cargo install but that's for dependencies), but since cargo supports third-party subcommands there is an answer: the cargo-update crate.
Install as usual with
cargo install cargo-update
then use
cargo install-update -a
to update all installed packages, for more usage information and examples see the cargo install-update manpage.
Disclaimer: am author
As of Rust 1.41.0, you can use the following command to update crates to their latest version:
cargo install <crate>
This came from pull request #6798 (Add install-upgrade) and was stabilized in #7560 (Stabilize install-upgrade).
How does it work?
Instead of failing when cargo install detects a package is already installed, it will upgrade if the versions don't match, or do nothing (exit 0) if it is considered "up-to-date".
Forcing an upgrade / re-installation
The following command will always uninstall, download and compile the latest version of the crate - even if there's no newer version available. Under normal circumstances the install-upgrade feature should be preferred as it does save time and bandwidth if there's no new version of the crate.
cargo install --force <crate>
Documentation
Further information can be found in the GitHub issue rust-lang/cargo#6797 and in the official documentation chapter.
A solution I've found is to add the --force flag to the install command. For example cargo install --force clippy. This will effectively re-install the latest version.
Here is a one-liner to update all installed Cargo crates, except those installed from a local folder:
cargo install $(cargo install --list | egrep '^[a-z0-9_-]+ v[0-9.]+:$' | cut -f1 -d' ')
Explanation:
List installed packages
Filter to lines which contain package names and versions, and exclude ones with filesystem paths
Cut those lines to only include the package name
cargo install with the resulting package names
I was hoping to use a library that is on Hackage. But it turns out that the maintainer of the package has abandoned the library for some time and now it's not compiling due to minor problems. Now that I fixed the problems, what is the best way to link it with my cabal project until my PR is merged into the upstream
To install it like "cabal install ..." would install it, try this:
Use "cabal get pkgname-X.Y.Z" to get the source from Hackage; it places the source in the directory pkgname-X.Y.Z
cd into the source directory and apply your patches
Run cabal install
There are other options if you are using stack or cabal sandboxes.