nis*_*ish 43 ruby-on-rails bundler
如何删除bundle install在特定RoR项目中使用的所有安装的gem .我不想卸载其他项目使用的gem.
rai*_*inz 28
既然我们正在使用ruby,你可以做这样的事情我想:
bundle list | ruby -e 'ARGF.readlines[1..-1].each {|l| g = l.split(" "); puts "Removing #{g[1]}"; `gem uninstall --force #{g[1]} -v #{g[2].gsub(/\(|\)/, "")}`; }'
Run Code Online (Sandbox Code Playgroud)
注意:只进行轻微测试.
Kap*_*ssi 13
没有一种简单的方法可以删除所有宝石 - 更不用说删除特定捆绑中的宝石了.您可以尝试以下建议: 在OSX中卸载所有已安装的宝石?
适应bundle show命令而不是gem list
对于未来,尝试这种方法:
如果您在本地安装捆绑包(如下例所示),则gems将不会安装在您的全局gem目录中.然后,您可以轻松删除安装文件夹以删除捆绑包的所有宝石.
# install gems to project_root/vendor/bundle
bundle install --path vendor/bundle --without test
Run Code Online (Sandbox Code Playgroud)
路径选项保存到.bundle/config就像所有其他一样,任何后续bundle install调用都会使用它,除非你把它设置为其他东西或从配置中删除它!
mar*_*ito 12
您可以使用(如Tobias所说,如果您使用的是RVM)
rvm gemset empty [gemset]
例如,直接在gemset上
rvm gemset empty 2.0.0@server
Run Code Online (Sandbox Code Playgroud)
小智 5
如果您使用的是 rvm,您当然可以卸载并重新安装安装了 gems 的 ruby 版本,即
% rvm use
Using /home/ubuntu/.rvm/gems/ruby-2.2.1
% rvm uninstall 2.2.1
ruby-2.2.1 - #removing rubies/ruby-2.2.1..
ruby-2.2.1 - #removing default ruby interpreter.............
% rvm install 2.2.1
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/14.0/x86_64/ruby-2.2.1.tar.bz2
Checking requirements for ubuntu.
Requirements installation successful.
ruby-2.2.1 - #configure
ruby-2.2.1 - #download
ruby-2.2.1 - #validate archive
ruby-2.2.1 - #setup
ruby-2.2.1 - #gemset created /home/ubuntu/.rvm/gems/ruby-2.2.1@global
ruby-2.2.1 - #importing gemset /home/ubuntu/.rvm/gemsets/global.gems..............................
ruby-2.2.1 - #generating global wrappers........
ruby-2.2.1 - #gemset created /home/ubuntu/.rvm/gems/ruby-2.2.1
ruby-2.2.1 - #importing gemsetfile /home/ubuntu/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.2.1 - #generating default wrappers........
Run Code Online (Sandbox Code Playgroud)
现在你有一个 ruby 环境,没有任何已安装的 gem。
实际上很简单
gem list --no-versions | xargs gem uninstall -a
Run Code Online (Sandbox Code Playgroud)
如果您未使用RVM / RBENV,则当gem尝试卸载可能失败的系统库时,您可能会遇到问题。在这种情况下,请一一调用uninstall命令以跳过这些命令。
gem list --no-versions | xargs -n1 gem uninstall -a
Run Code Online (Sandbox Code Playgroud)
来自https://makandracards.com/jan0sch/9537-uninstall-all-ruby-gems-from-your-system 的另一种方式(类似于rainkinz 的回答和Ralph 的评论)。以下是一些变化:
# if you're the root user:
gem list | cut -d" " -f1 | xargs -I % gem uninstall -aIx %
# if you're a non-root user:
gem list | cut -d" " -f1 | xargs -I % sudo gem uninstall -aIx %
# docker compose (if your service is named "web" running the root user):
docker-compose run web bash -c 'gem list | cut -d" " -f1 | xargs -I % gem uninstall -aIx %'
####
gem install bundler
# or if using docker compose:
docker-compose run web gem install bundler
# optionally reinstall gems:
bundle install
# or if using docker compose:
docker-compose run web bundle install
Run Code Online (Sandbox Code Playgroud)
打破这个:
gem list 列出所有宝石cut -d" " -f1 取第一列xargs -I % gem uninstall -aIx %调用gem uninstall -aIx与各输出线作为参数请注意,我使用-Ias指定了参数%并直接传递了它以确保安全:
xargs -I % gem uninstall -aIx %
Run Code Online (Sandbox Code Playgroud)
代替:
xargs gem uninstall -aIx
Run Code Online (Sandbox Code Playgroud)
那是因为xargs存在安全问题,其中-n可以将诸如选项传递给其命令并导致意外结果。这可以通过以下示例进行演示:
# correctly prints "-n hello" (with trailing newline):
echo '-n Hello' | xargs -I % echo % | xargs -I % echo %
# incorrectly prints "hello" (without trailing newline):
echo '-n Hello' | xargs echo
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
48135 次 |
| 最近记录: |