MacDownApp / macdown

Open source Markdown editor for macOS.
https://macdown.uranusjr.com/
9.45k stars 1.09k forks source link

bundle installation #1163

Open wenq1 opened 4 years ago

wenq1 commented 4 years ago

New to ruby. Asking a few basic questions:

With a normal user, bundle install returns:

Your user account isn't allowed to install to the system Rubygems.
You can cancel this installation and run:

    bundle install --path vendor/bundle

to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to Rubygems using sudo.

After continuing,

Gem::InstallError: minitest requires Ruby version ~> 2.2. An error occurred while installing minitest (5.14.0), and Bundler cannot continue. Make sure that gem install minitest -v '5.14.0' succeeds before bundling.

My ruby version is: wc$ ruby --version ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17]

With root user (which i don't like), it prompted immediatly as follows:

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application
for all non-root users on this machine.
Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
FranklinYu commented 4 years ago

Hi there, welcome to Ruby. Are you familiar with any other scripting language like Python or JavaScript? Would make it easier to explain RubyGems and Bundler in that case.

wenq1 commented 4 years ago

Yep. I use Javascript mainly.

wenq1 commented 4 years ago

I'm actually thinking about making an electron version of the editor. Reason being it will be able to be integrated to our team website which is built entirely using react and css.

FranklinYu commented 4 years ago

Ok. So NPM by default installs packages locally in the project (in node_modules folder), while RubyGems in contrast installs globally (think about npm install --global). The exact folder of the global gem repository depends on where you installs the package manager (this is true for both NPM and RubyGems), and some of those folder may require root permission (technically speaking it’s permission of owner of the folder).

If you want local installation like NPM, then go with the --path option to pass the local folder; current version of Bundler should be able to remember this folder so you only specifies it once. vendor/bundle is just a convention; actually anywhere works.

If you want to install it globally you can simply run bundle install and it should prompt for password (it’s using sudo internally; if no prompt then it’s a bug). I wouldn’t recommend this path for you though, because

  1. This is different from the NPM way, which you are already familiar.
  2. Since you are asking this question, this project may well be your only Ruby project, so there is no benefit of sharing packages anyway.

You can always learn global package (where they are, best practice, etc.) when you need to.

rschiang commented 4 years ago

@wenq1 Usually the best practice is to leave the system ruby installation alone, and use version management utilities e.g. rbenv to sideload ruby installations. Not only will you be able to install new gems without the need of root permission, it also prevents you from unknowingly breaking other applications outside of terminal.

rbenv install 2.7.0 && rbenv shell 2.7.0
gem install bundler
bundle install