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 have GCC v9. But I'm trying to install a GCC 4.8.1 version to test a library compilation on that very old version of GCC.
The version is not available in the official Ubuntu repos,it is deprecated, but I've found it in other mirrors as told by the official GCC website. This one seems like popular one:
https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
I have very little knowledge of linux package systems except for the basic. I want to keep both versions. So I should do this:
sudo apt -y install gcc-4.8.1 gcc-9
The reason why I want to use this command and not install it from the file, apart from the difficulty of doing that for me, is that I'm following a guide in order to have several GCCs on my system:
https://www.fosslinux.com/39386/how-to-install-multiple-versions-of-gcc-and-g-on-ubuntu-20-04.htm
When I add the url to the sources.list file seems like it is working.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update -q
But when I try to call the install with gcc-4.8.1 or gcc-4.8 , or even gcc-4 the package doesn't exist.
Package gcc-4.8 is not available, but is referred to by another
package. This may mean that the package is missing, has been
obsoleted, or is only available from another source E: Package
'gcc-4.8' has no installation candidate
Also, I don't know if websites like these can be added to the repos list in order to find the package using APT:
http://www.netgull.com/gcc/releases/gcc-4.8.1/
[EDIT]
I downloaded the package from the website I linked. I have no idea how to install this by hand. If only I could find a repository that could help me with this... I have no idea how to make APT help me with the installation.
But I'm trying to install a GCC 4.8.1 version to test a library compilation on that very old version of GCC.
Developers have tools up their sleeve so they don't have to install dependencies and bloating their systems for every library (and every configuration of that library!) they want to try out and test.
Use docker. You could write for example a testing script, assuming your project uses make:
# test_my_lib_in_gcc-4.8.sh
#!/bin/sh
docker run -ti --rm -v $PWD:/project -w /project gcc:4.8 -u $UID:$GID sh <<EOF
make && make test
EOF
that will compile and test your application in using 4.8 gcc. Consider how easy it is to change gcc version - just change the number. You could test your library in gcc, in different versions, and using other compilers and on different distributions to make sure it works for others. If you're a developer of the library, write an automatized CI pipeline that would automatically test your application each commit in specific docker environment, using ex. https://docs.gitlab.com/ee/ci/README.html or https://travis-ci.org/ .
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'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 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