Ubuntu上构建Ruby on Rails遇到的小问题和解决方法

来源:互联网 发布:阿里云免费网站空间 编辑:程序博客网 时间:2024/05/17 03:22

在Ubuntu上安装 Ruby on Rails 和 Postgresql 数据库的时候遇到的一些小问题,特别在这里分享下解决方法,如果对大家有用,希望还能留几句话哈~

Ruby用RVM安装自己要的版本应该不会有太多的问题 RVM网址:https://rvm.io/rvm/install

Rails安装只要在Ruby安装完后,执行命令 gem install rails 即可,一般没有什么问题,能够顺利安装.


遇到的问题有

1.安装完rails之后,启动rails服务器的时候,出现错误 Could not find a JavaScript runtime.

  懂英文的孩纸应该都知道了是什么错误,不多说.

  解决方法:

vim Gemfile

  进入到Gemfile.这里能看到所有的Gem.如果你缺少  gem 'therubyracer' 和 gem 'execjs' 这两个gem,那就手动加上.

        tips: 这里需要安装一下vim对文件进行打开和修改

:q
  退出Gemfile.然后,执行bundle重新安装gem.搞定!


2.在装Postgresql的时候也会有问题

  可能有不少人遇到过一下的错误

Building native extensions.  This could take a while...ERROR:  Error installing pg:        ERROR: Failed to build gem native extension.        /export/home/invantest/tools/ruby/1.8.7/bin/ruby extconf.rb --with-pg-config=/export/home/invantest/tools/pgsql/8.3.3/bin/pg_configUsing config values from /export/home/invantest/tools/pgsql/8.3.3/bin/pg_configchecking for libpq-fe.h... noCan't find the 'libpq-fe.h header*** extconf.rb failed ***Could not create Makefile due to some reason, probably lack ofnecessary libraries and/or headers.  Check the mkmf.log file for moredetails.  You may need configuration options......

  这时候使用以下命令安装一下"libpq-dev"包,其中有libpq-fe.h

sudo apt-get install libpq-dev


3. 如果遇到没有用户能够进入postgresql数据库

        进入到数据库 用sql语句创建一个用户即可,如果创建后,还遇到错误提示

psql: FATAL: role "youruser" is not permitted to log in

        那再进入数据库 运行如下sql语句即可

postgres=# alter role youruser LOGIN;

原创粉丝点击