简体   繁体   中英

How to check if a particular package was installed on linux with rake?

During my attempt to automate some task with rake on ubuntu, I've encountered scenarios that required packed might not already exist on target machine. What is a good way to check if certain package was already installed on the system and respond accordingly?

For example, I'd like to run 'npm start' within certain task, but I'd want to know if npm has already been installed on the system, thus giving user the correct error message. I'm also fine doing it with thor if it's possible at all.

You can run system command from Ruby scripts using the Kernel.system method. Consider something like the following:

fail unless system('which npm')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM