-
-
Save peter/3025502 to your computer and use it in GitHub Desktop.
# 0. Make sure you have Ruby 1.9.3 installed, and optionally RVM and PostgreSQL | |
# 0.2 If you are on the Mac, make sure you have a c compiler by installing XCode Command Line Tools or gcc4.2 with homebrew | |
# https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers | |
# 0.5 Make sure you have bundler version ~> 1.2 as Rails depends on it | |
gem install bundler | |
# 1. Get edge Rails source (master branch) | |
git clone https://github.com/rails/rails.git | |
# 2. Create the rails app | |
# The --edge option will point the Gemfile to rails on github (the tip of the master branch, i.e. EdgeRails) | |
# Use the --dev option to insated point your Gemfile to your local rails checkout (useful for experimentation) | |
rails/railties/bin/rails new myapp --edge --skip-bundle --database=postgresql --skip-test-unit --skip-index-html | |
# 3. (Optional) Create rvm gemset on Ruby 1.9.3 (Rails 4 requires Ruby 1.9.3) | |
# This step will isolate the gem dependencies of the app from other gems installed on your system | |
rvm --rvmrc --create 1.9.3@myapp | |
# 4. (Optional) Install gem dependencies and put binaries under ./bin | |
# If you skip this step you need to prefix commandline commands with "bundle exec" | |
# NOTE: I had to do the following on my mac for the gcc compiler to be found when the json gem was installed: | |
# sudo ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2 | |
bundle install --binstubs | |
# 5. Set up PostgreSQL database | |
createuser myapp | |
bin/rake db:create | |
# 6. Scaffold some model to test that the app works | |
bin/rails generate scaffold Post title:string body:text | |
bin/rake db:migrate | |
bin/rails server | |
# Add root to: 'posts#index' in config/routes.rb | |
open http://localhost:3000 | |
# 7. Create repo on github | |
# Browse to http://github.com to click the "New repository" button | |
git init | |
git add . | |
git commit -m "First commit" | |
git remote add origin git@github.com:peter/myapp.git # use the URL from github here | |
git push -u origin master | |
# 8. Deploy to Heroku | |
gem install bundler --pre # Needed to specify ruby 1.9.3 for Heroku | |
# Add gem 'thin' to Gemfile # Typical web server for Heroku deploy | |
# Add ruby '1.9.3' to Gemfile (after the source directive) | |
# Add config.assets.initialize_on_precompile = false to config/application.rb # Avoid db connect on asset precompile | |
RAILS_ENV=production bin/rake assets:precompile | |
# (See https://devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar for more info) | |
# NOTE: to get eventmachine (thin dependency) to install on my Mac (Mountain Lion) I had to do: | |
# sudo ln -s /usr/bin/llvm-g++-4.2 /usr/bin/g++-4.2 | |
# See: https://github.com/eventmachine/eventmachine/issues/325 | |
bundle install | |
echo "web: bundle exec rails server thin -p \$PORT -e \$RACK_ENV" > Procfile | |
git add .; git commit -m "Preparations for Heroku deploy"; git push | |
heroku apps:create peter-myapp # myapp was taken... | |
git push heroku master | |
heroku run rake db:migrate | |
heroku restart | |
heroku apps:open | |
heroku logs --tail |
Ok this is really kicking my butt and irritating me. I'm running windows, and I'm assuming that's probably my first problem!
I followed all of the steps in here and still cant deploy to Heroku. I decided to go ahead and do: gem install rails --pre in order to have the rails 4 beta gem installed. The application works perfectly on my local machine for development and test.
I can do "git push heroku master" without any issues, it's the "heroku run bin/rake db:migrate" that keeps saying "/usr/bin/env: ruby.exe: No such file or directory" ...I even tried "heroku run rake db:migrate"
For sanity I went ahead and created a rails 3.2 application and tried to deploy to Heroku and I had no problems at all. I only have issues with the rails 4 deploy. I did notice that the rails 4 application has a bin directory, where the rails 3.2 does not, and that one of the files under it is Rake; does this have something to do with it?
I'm new to Ruby and Rails, but I've been programming for 4 years as a C# asp .net developer for a large corporation. I must say I love RoR MUCH MORE than what I do ...I just wish I could get this working. This is 2 days I've been trying to fix this.
Thanks in advance!
Untill heroku won't support the new manifest-xxx.json file the assets will be needed to be served by the rails server itself.
@orbanbotond I'm not sure I understand. I'm sorry, pretty new to Ruby on Rails. I followed the steps above (except I didn't understand "RAILS_ENV=production bin/rake assets:precompile" or where you do that at. I did also follow jgeiger's message about config.serve_static_assets = true.
However, this is what I get after successfully doing a git push heroku master:
c:\Sites\test_app>heroku run rake db:migrate
Running rake db:migrate
attached to terminal... up, run.2675
/usr/bin/env: ruby.exe: No such file or directory
And I also did some diagnosis on the Heroku server:
c:\Sites\test_app>heroku run bash
Running bash
attached to terminal... up, run.8879
~ $ cd ..
cd ..
/ $ cd usr/bin/
cd usr/bin/
/usr/bin $ env
env
TERM=
OLDPWD=/
RACK_ENV=production
HEROKU_POSTGRESQL_WHITE_URL=postgres://icblnmrkzbmugi:2pmUQikNEO4kNFXyvJnyC1rzMj@ec2-107-22-164-173.compute-1.amazonaws.com:5432/de2hcbbv3rjl31
PATH=/app/bin:/app/vendor/bundle/ruby/1.9.1/bin:bin:vendor/bundle/ruby/1.9.1/bin
:/usr/local/bin:/usr/bin:/bin
PWD=/usr/bin
PS=run.8879
LANG=en_US.UTF-8
PS1=[\033[01;34m]\w[\033[00m] [\033[01;32m]$ [\033[00m]
HOME=/app
SHLVL=2
RAILS_ENV=production
GEM_PATH=/app/vendor/bundle/ruby/1.9.1:
PORT=8871
DATABASE_URL=postgres://icblnmrkzbmugi:2pmUQikNEO4kNFXyvJnyC1rzMj@ec2-107-22-164-173.compute-1.amazonaws.com:5432/de2hcbbv3rjl31_=/usr/bin/env
/usr/bin $ ruby -v
ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]
/usr/bin $ ruby rake db:migrate
ruby rake db:migrate
ruby: No such file or directory -- rake (LoadError)
/usr/bin $ rake db:migrate
rake db:migrate
/usr/bin/env: ruby.exe: No such file or directory
/usr/bin $ cd ..
cd ..
/usr $ cd ..
cd ..
/ $ cd app/bin
cd app/bin
~/bin $ ls
ls
bundle gem rackup rake2thor ruby scss thin tt
erb irb rails rdoc sass sprockets thor
erubis node rake ri sass-convert testrb tilt
~/bin $
You can see that PATH has /app/bin in it, and when i run "ruby -v" I do in fact get the ruby version, yet when I try to run anything to do with ruby.eve, I get the "No such file or directory" error. If I were to change directory to /all/bin and run "ruby rake db:migrate" it would work fine.
I thought I was okay with doing "ruby rake db:migrate" from /app/bin as it accomplished what I needed to do, but when I navigated to the URL for my test application site, it threw an error. I then did "heroku logs" from my windows command prompt and it was littered with the same error "/usr/bin/env: ruby.exe: No such file or directory"
I have also posted for help on StackOverflow: http://stackoverflow.com/questions/15443456/windows-heroku-run-rake-dbmigrate-error-usr-bin-env-ruby-exe-no-such-file-o
I appreciate any help you all can provide ...obviously others have been successful at pushing a Rails 4 application. I'm almost considering restarting my application as a Rails 3.2 app as this is completely frustrating ...I just don't wan tto give up!
Also worth noting: In some circumstances, you may get an error about railties not being found in the to_spec
method; running bundle install --binstubs
solves this.
@Kabniell FYI I found this gist via google and you've posted your database credentials in your last comment. May want to edit them out.
The above proposed fixes didn't work for me, but turning on this lab feature did: https://devcenter.heroku.com/articles/labs-user-env-compile
Not sure I like this solution, but it's good for now.
@jgeiger Thanks - that isn't intuitive but it's apparently necessary (fixed my problem of assets not being found).