How do I properly install and run Thin? - ruby

How does one install and run Thin? According to the official page, I can start it with bundle exec thin start, but no dice. Instead I get Could not locate Gemfile. If I restart Terminal and run gem install thin again, it seems to install it again as if it weren't properly installed the first time.

The guide assumes you're using it in a Ruby project. Using bundle ... requires there to be a Gemfile in the current directory. It'll work if you cd to a Ruby project and add gem thin to your Gemfile.
Here's some info on Gemfiles: http://bundler.io/v1.3/gemfile.html

Related

tootlcrl error: Could not find concurrent-ruby-1.1.10 in any of the sources

I'm trying to run a tootctl command, but am running into a problem with it not being able to detect the required dependency is not present.
Could not find concurrent-ruby-1.1.10 in any of the sources
I have run bundle install and the gems get installed (or are confirmed already installed), but the command still has trouble not finding the
Using concurrent-ruby-1.1.10
...dozens of other packages
Using rails-settings-cached 0.6.6
Bundle complete! 122 Gemfile dependencies, 225 gems now installed.
Gems in the groups 'development' and 'test' were not installed.
Bundled gems are installed into `../vendor/bundle`
then I attempt the command again..
me#mastodon-vm:/var/www/mastodon/bin$ ./tootctl media remove --days=7
Could not find concurrent-ruby-1.1.10 in any of the sources
Run `bundle install` to install missing gems.
me#mastodon-vm:/var/www/mastodon/bin$
but I'm back to the same problem. What is the typical approach to fix this?
Note: I did try to follow the guidance in this SO post, but it broke the entire installation. I was able to save it by replacing Gemfile and Gemfile.lock from Mastodon's source (phew)
Your log shows
Gems in the groups 'development' and 'test' were not installed.
Try to install your Gems with
bundle install --with development test
or run
RAILS_ENV=production tootctl
According to https://rubygems.org/gems/concurrent-ruby/versions/1.1.10 the gem is named "concurrent-ruby". When I run gem install concurrent-ruby, it is installed successfully on my computer.

Can't install gem using Bundler's Rakefile install task when developing a custom gem

I'm developing a couple of private gems and I think I don't understand correctly the PATH/GEM_PATH and/or Bundler/RVM installation flow, would love if someone could chip in.
I have a repository with two gems (A & B for simplicity sake). I've developed the gems using the scaffolding + following the guidelines provided by this bundler tutorial.
Thanks to the Bundler project I have a few Rakefile tasks like rake build, rake install, rake install:local and rake release. Because of the private nature of these gems I can't release them to RubyGems (and we haven't looked into hosting our rubygems).
My machines are using RVM to manage ruby versions and Bundler version 1.15.1
What I want to do: Assuming a new machine/developer trying out the project, ideally we would cd into each of the subfolders (currently 2, gem A and gem B), run rake install and after that we should have the gems available system wide for the current user.
What is happening: The gems are built and work properly, but they are only available inside the subfolder of each gem i.e. gem A is only available inside the subfolder A and gem B is only available inside subfolder B.
What I've tried: So, after rake build/install/install:local a new .gem file is generated under pkg. I've tried to manually install the "compiled" file using gem install pkg/A.gem, gem install --local pkg/A.gem and gem install --local --user-install pkg/A.gem without success. (there are plenty of SO questions/answers about this)
I believe this has something to do with the PATH variables, but like I said before I don't fully understand the way they are managed. I get the following results from these commands:
# Our gem
> gem which A
/home/ubuntu/.rvm/gems/ruby-2.4.0/gems/A-0.1.8/lib/A.rb
# Pry, available globally
> gem which pry
/home/ubuntu/.rvm/gems/ruby-2.4.0/gems/pry-0.11.1/lib/pry.rb
I've been lost and frustrated for far too long now, any help is appreciated. Also open to hear suggestions of better private gem installation flows :)
Yes, it has something to do with your PATH variables. Your installation seems to be good.
I advise you to first affirm your gems installation path with:
echo $GEM_HOME
The double check your PATH to ensure its present and also confirm that the GEM home is also where the gem got installed into from the rake install
echo $PATH
If not, put it in your path and you should be fine with something like this:
echo PATH=$PATH:$GEM_HOME >> ~/.bashrc
source ~/.bashrc
Build your gem as per that guide you linked. You should end up with a gem file. Distribute this as you see fit (I use rsync/crontab to download newer gem versions but anything goes). User can install the gem as follows:
gem install --user-install /path/to/your/file.gem
This will install the gem in the user's ~/.gem/ruby/<version>/gems/<your-gem-name> directory.
Tried it with an empty gem (foodie, as in that example guide) and it works fine. But if you don't specify the --user-install parameter it will try to install in the system ruby dir (/usr/lib/ruby/gems...)

How to install additional gems with bundler in production environment?

I have a staging server. And I've got some issue I'd like to investigate right there. But I forgot to add byebug to Gemfile. I can surely add it locally, run bundle, commit to repository, deploy. But isn't there an easier way?
When I try to change Gemfile remotely and run bundle I get:
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
If this is a development machine, remove the /home/gccs/website-backend/releases/20161018143057/Gemfile freeze
by running `bundle install --no-deployment`.
You have added to the Gemfile:
* byebug
Gems are installed with capistrano, basically, like so:
bundle install --path /home/user/app/shared/bundle --without development test --deployment --quiet
Edit .bundle/config changing BUNDLE_FROZEN: '1' to '0' (or removing it) is enough in order to be allowed by Bundler to manage gems in a deployment environment. Then you can edit the Gemfile, run bundle, restart your application and the custom gems are ready to be used.
If you intend to use them outside of the application runtime (f.e. if you need pry in rails console) restarting the server is not needed.
The reason why you're unable to install additional gems is because the bundle is frozen. You can check it like so:
$ grep FROZEN .bundle/config
BUNDLE_FROZEN: '1'
If you remove the line (as suggested by mdesantis) or change "1" to "0", you'll be able to install whatever gems you like, as if it were developer machine. But generally it's best to restore the value, if no more needed. Not sure if bundler will do that automatically on next deploy.

Gems install under vendor/bundle in rails app local testing

I have a rails app that I'm running locally where the gems are installed in the vendor/bundle directory. I want to add some debugging statements to a gem and then test it locally. I'm running bundle exec rackup config.ru to run the server. I've tried rerunning bundle install before starting the application, but that still doesn't seem to pick up my changes. Any ideas?
Running bundle show --paths will print out exactly where Bundler is loading your gems from, so you can double-check that against the files you are editing.
As a shortcut, bundle open <gemname> will open that gem's directory in your editor of choice (whatever your EDITOR environment variable is set to). You can then edit it directly there.
There is normally no need to re-run bundle install or rebuild the gem when you edit files this way.

Using Bundler in deployment

Pretty fundamental question but I'm trying to understand how best to use Bundler in a deployment situation.
I'm working on a Sinatra application that has about 20 dependent gems. During development, I'm using RVM with a custom gemset for the application, and I run bundle install to update the gemset in accordance with the gemfile.
When it comes to deployment (manually for now, so I can understand how it all works before using a tool like capistrano), I need to do bundle install --development right? This downloads the gems and places them in vendor/bundle.
My question is what else do I need to do? I'm using Unicorn on the server - do I just bundle exec unicorn ... and everything just works? (i.e. bundler finds the vendor directory and uses the gems from there?)
Should unicorn be a vendored gem in the application or a separate 'system' gem on the server that all applications share?
You need --deployment key, not --development: http://gembundler.com/man/bundle-install.1.html#DEPLOYMENT-MODE
On first run bundler creates config in .bundle directory. You can check it by running bundle config or just cat .bundle/config in project's directory. So bundle exec unicorn is enough since bundler knows where gems are installed. On development machine you can also install gems to arbitrary directory using --path key. For more details see manpage for bundle install (link above or bundle help install).

Resources