执行bundle exec rake db:create报错Operation not permitted求解决
rake db:create时遇到Errno::EPERM权限错误 Hey there! Let's work through this permission issue together—super common when you're just starting out with Rails and RVM, so don't stress. Here are the most reliable fixes to try:
修复项目目录与bundle文件夹的权限
First, make sure your project folder and thevendor/bundledirectory are owned by your user (not root, which often causes permission blocks). Run these commands from your project root:sudo chown -R $USER:$USER /Users/ravibhatia/Desktop/Dev Code/fountain chmod -R 755 /Users/ravibhatia/Desktop/Dev Code/fountain/vendor/bundleThe
chowncommand transfers full ownership of the project to your user account, whilechmodsets safe, accessible read/write/execute permissions.重新安装bundle依赖(重置权限)
Sometimes the initial bundle installation creates files with messed-up permissions. Let's wipe the old bundle folder and start fresh:rm -rf vendor/bundle bundle install --path vendor/bundleThis deletes the problematic bundle directory and reinstalls all dependencies using your user's permissions, avoiding root-owned files entirely.
修复RVM自身的权限
Since you're using RVM, it's possible the Ruby installation directory has incorrect ownership. Use RVM's built-in fix command to sort this out:rvm fix-permissionsThis command automatically corrects ownership for all RVM-managed rubies, gems, and related files—no manual digging required.
绝对不要用sudo(划重点!)
I know it's tempting to slapsudoin front of the command to force it through, but this will only make things worse long-term. It creates root-owned files that your regular user can't access later, leading to more permission headaches down the line. Stick to the fixes above instead.检查macOS系统完整性保护(仅针对Mac用户)
If you're on macOS, System Integrity Protection (SIP) might block access to certain directories (though your Desktop folder shouldn't be affected). You can check SIP's status with:csrutil statusIf it's enabled and you suspect it's causing issues, disabling it temporarily can help—but only do this as a last resort, since SIP is a critical security feature.
After trying these steps, run bundle exec rake db:create again—it should execute without the permission error!
内容的提问来源于stack exchange,提问作者Ravi Bhatia

