raco: How to install a package or update it if it already exists?
raco: How to install a package or update it if it already exists?
raco pkg install <package-name> installs a package if it does not yet exist, and fails if the package already exists. raco pkg update <package-name> updates a package, and fails if the package does not yet exist.
raco pkg install <package-name>
raco pkg update <package-name>
Is there a raco command that combines both commands? In other words, is there a command that can install a package if it does not exist, and also update the package if it already exists?
Rationale: This kind of command would be useful in shell scripting. For example, in Debian/Ubuntu, the apt-get install command has the exact required behaviour, and for python, pip install --upgrade has that too. Is there an equivalent for raco?
apt-get install
pip install --upgrade
Racket version: 6.11
1 Answer
1
You can use raco pkg show <package> to detect if a package is installed, for example with something like:
raco pkg show <package>
mypkg='memoize'
if [ " [none]" = "$(raco pkg show '$mypkg' | tail -1)" ]; then
raco pkg install "$mypkg"
else
raco pkg update "$mypkg"
fi
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.