[英]How do I install rails and create a new application without root access?
I am trying to install Ruby on Rails on a Linux machine in my home directory (without root access). 我正在尝试在我的主目录中的Linux机器上安装Ruby on Rails(无root访问权限)。 My ruby version is
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]
. 我的ruby版本是
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]
。 So far I was able to: 到目前为止,我能够:
$ gem install --user-install rails
which apparently has installed rails
into ~/.gem/ruby/2.1.0/bin/rails
: 显然已经将
rails
安装到~/.gem/ruby/2.1.0/bin/rails
:
$ ./.gem/ruby/2.1.0/bin/rails --version
Rails 4.2.6
But then it fails to create the application: 但是随后它无法创建应用程序:
$ ~/.gem/ruby/2.1.0/bin/rails new myapp
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/javascripts/application.js
create app/assets/stylesheets/application.css
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/views/layouts/application.html.erb
create app/assets/images/.keep
create app/mailers/.keep
create app/models/.keep
create app/controllers/concerns/.keep
create app/models/concerns/.keep
create bin
create bin/bundle
create bin/rails
create bin/rake
create bin/setup
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/secrets.yml
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/assets.rb
create config/initializers/backtrace_silencers.rb
create config/initializers/cookies_serializer.rb
create config/initializers/filter_parameter_logging.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/session_store.rb
create config/initializers/wrap_parameters.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create lib
create lib/tasks
create lib/tasks/.keep
create lib/assets
create lib/assets/.keep
create log
create log/.keep
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/robots.txt
create test/fixtures
create test/fixtures/.keep
create test/controllers
create test/controllers/.keep
create test/mailers
create test/mailers/.keep
create test/models
create test/models/.keep
create test/helpers
create test/helpers/.keep
create test/integration
create test/integration/.keep
create test/test_helper.rb
create tmp/cache
create tmp/cache/assets
create vendor/assets/javascripts
create vendor/assets/javascripts/.keep
create vendor/assets/stylesheets
create vendor/assets/stylesheets/.keep
run bundle install
There was an error while trying to write to `/var/lib/gems/2.1.0`. It is likely that you need to
grant write permissions for that path.
run bundle exec spring binstub --all
bundler: command not found: spring
Install missing gem executables with `bundle install`
Does rails require root access?? Rails是否需要root访问权限?
Thanks! 谢谢!
A typical development environment is set up with RVM (or rbenv
, never tried it) and is contained entirely in your home folder: Ruby interpreter (possibly more than one!), its gems and configuration . 一个典型的开发环境是使用RVM (或
rbenv
,从未尝试过)设置的,并且完全包含在您的主文件夹中: Ruby解释器 (可能不止一个!),它的gems和configuration 。 For that you don't need root access. 为此,您不需要root访问。
When installing Ruby via RVM, you might get a prompt for installing dependencies required to compile Ruby from sources. 通过RVM安装Ruby时,可能会提示您安装从源代码编译Ruby所需的依赖项。 That's one case.
那是一种情况。 (And, as it turns out, this may fail if
sudo
is not available, and it might be, so see this question for possible alternatives ) (而且,事实证明,如果
sudo
不可用,可能会失败,所以可能会失败,所以请参阅此问题以获取可能的替代方法 )
You might occasionally need root access for installing development libraries needed to compile native extensions for certain gems. 您有时可能需要root用户访问权限才能安装开发库,这些开发库需要编译某些gem的本机扩展 。 For instance, for gem
pg
you'll need libpq-dev
on Debian and derivatives (Ubuntu, Mint, etc.). 例如,对于gem
pg
您需要在Debian及其衍生产品(Ubuntu,Mint等)上使用libpq-dev
。 While you could try downloading the sources to your home folder and point the compiler in that direction, that takes time. 虽然您可以尝试将源下载到主文件夹中,然后将编译器指向该方向,但这会花费一些时间。 So that's two cases.
这是两种情况。
In your specific case rails
has done the job just fine: it generated the template, it just failed to bundle install
the template's dependencies. 在您的特定情况下,
rails
很好地完成了这项工作:它生成了模板,但bundle install
模板的依赖项失败。 It uses whatever gem directory is default for RubyGems. 它使用RubyGems默认的gem目录。 Seeing that it's
/var/lib/gems/2.1.0
, I'm guessing you're using system-wide Ruby . 看到它是
/var/lib/gems/2.1.0
, 我猜您正在使用系统范围的Ruby 。 This isn't ideal for development as you might want to switch back and forth between different interpreter versions (or even implementations, such as Rubinius), use a version manager constrained to your home folder. 对于开发而言,这不是理想的选择,因为您可能希望在不同的解释器版本(甚至是实现,例如Rubinius)之间来回切换, 使用受限于主文件夹的版本管理器 。
Not that you can do nothing else. 不是说你无能为力。 Try
cd
ing into the generated folder and running: 尝试
cd
进入生成的文件夹并运行:
bundle --help install
There are many options, you see. 您会看到很多选择。
--path
or even --standalone
can probably save you here, it overrides gem installation path and remembers the fact that it's overridden, so it knows where to look for gems. --path
甚至--standalone
可能会在这里保存您的位置,它会覆盖 gem的安装路径,并记住它已被覆盖的事实,因此它知道在哪里查找gem。
Anyway, once the application is set up and dependencies are resolved and installed, you won't need root access for neither running it (on non-privileged ports, of course) or setting up another application, since any necessary system-wide dependencies will already be installed by then. 无论如何,一旦安装了应用程序并解决并安装了依赖项,您将不需要root访问权限即可运行它(当然是在非特权端口上)或设置另一个应用程序,因为任何必要的系统范围的依赖项都将届时已安装。
As I know, Ruby on Rails application require root access by default for install gems. 据我所知,Ruby on Rails应用程序默认需要root权限才能安装gem。 Possible it may be configured, but there is more simple solution - Ruby Version Manager or something similar.
可能已经配置好了,但是还有更简单的解决方案-Ruby Version Manager或类似的东西。
Rvm installs ruby gems in user's home directory and root access doesn't required for gems installing. Rvm在用户的主目录中安装ruby gem,并且不需要root访问权限即可安装gem。 Excepts unnecessary root Rvm allows to run different Ruby environments (eg different Ruby or RoR versions) in one user profile.
除了不必要的root Rvm允许在一个用户配置文件中运行不同的Ruby环境(例如,不同的Ruby或RoR版本)。
And look how to install Rvm without root access, look eg here , here or find it yourself 并查看如何在没有root用户访问权限的情况下安装Rvm,例如在此处 , 此处或自行查找
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.