I am trying to move to GVim(cream) as my primary editor on Ubuntu. I am using the wonderful rails.vim, however I also am using RVM.
Rvm works fine when doing things in a shell, and the ruby version I would like to use in rails.vim is the version set as default (but not the system version).
When I try to run things like
:Rgenerate migration migration_name
I get:
...
Missing Rails 2.3.8 gem.
...
If I try:
:!rvm use default
I get:
/bin/bash: rvm: command not found
Obviously cream/gvim is not using my .bashrc. What can I do to remedy this and get it working? Thanks.
Try running cream from the command line, if this solves the issue you can point your menu item to a script that opens cream in the context of a bash prompt.
This is because you are sourcing the rvm scripts in your .zshrc file. MacVim does not source the .zshrc file, but will source the .zshenv file.
Add following line to your .vimrc file.
set shell=/bin/sh
You probably have used .bash_profile to add RVM stuff to your bash environment. Alas, ~/.bash_profile won't normally be read by X startup scripts, as stated in Ubuntu Help
Use .profile or .bashrc. The .profile is only sourced by bash if .bash_profile is not there. I would use .bashrc.
rvm is a bash function, which changes bash environment. Seems like it is not supposed to be run from inside vim. You can't change the environment of an already-running program.
Try rvm gem list to make sure the rails gem is actually installed. rails (2.3.8) should be listed. If its not run rvm gem install rails.
I'm a vim user, and rvm + rails.vim works fine for me. Including your :Rgenerate example.
rvm is set on a per shell basis, so if you launch a new window or a new tab and you are using something other than your default interpreter and gemset you need to first
rvm gemset use my_rails238_gemset
and then
vim myshiz
Add this line to your ~/.bashrc:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
And make sure it comes before [ -z "$PS1" ] && return which stops sourcing the rest of the file if bash is not interactive.
And then add this to your ~/.profile:
export BASH_ENV=$HOME/.bashrc
With this line bash will now source $HOME/.bashrc when it is running non-interactively too.
Both GVim and shell scripts that you execute by double clicking should use RVM now.
Note: Only :! (ex: :!ruby, :!echo) commands will use RVM as commands like :ruby and :echo do not run bash and therefore do not source ~/.bashrc.
Running gvim from the command line doesn't work for me (in the sense that it's not acceptable).
When I am using a GUI application, I want to use it like a GUI, without a useless shell lingering in the background.
The 'set shell=' trick that works for Mac users doesn't work for me. Like you, I am using Ubuntu. Even setting the shell to /bin/bash doesn't do it.
The only thing I've gotten to work is this. First of all, install rvm.vim in addition to rails.vim.
Then, when you open gvim/cream, navigate to your project's root folder then type
:Rvm
This will cause rvm.vim to read your .ruby-version (or .rvmrc) file and initialize itself properly.
At this point,
:Rake
:Rgenerate
...and other rails.vim commands should work just fine.
Note that you can also pass arguments to :Rvm just as you would when running rvm from the shell.
Related
I am very new to Ruby on Rails. I have installed ruby, rails, gems, and RVM (and possibly some more RoR-associated files) via Mac OS terminal.
When I first installed these softwares, they seemed to work fine, and I could execute command lines like:
rails new 'project' or rails server
But then I messed around with git, directory, and some sudo bundle/gem commands a little bit because "bundle install" command wouldn't work. Honestly, I don't know what I have done, but all of these command lines have stopped working now.
They output various error messages, such as:
1) There was an error parsing 'Gemfile': Undefined local variable or method for Gemfile. Bundler cannot continue.
2) bash: /usr/local/bin/rails: /usr/local/opt/ruby/bin/ruby: bad interpreter: No such file or directory
3) ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions
4) find spec_for exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)
I think there were more errors, but these are all I can remember for now. Obviously, I am getting some intimidating error messages that I don't understand.
So I have come to a conclusion that I should uninstall all Ruby, Rails, Gems, RVM, and Homebrew files. But even this task looks very challenging to me.
I have tried numerous command lines in an attempt to delete them, but when I type in "rails" on spotlight, I still see lots of rails-associated files. Also, when I type "ruby -v" on terminal, it is still showing the ruby 2.0.0p648 version.
When I type in "which ruby" on terminal, it says "/usr/bin/ruby
When I type in "which rails" on terminal, it says "usr/local/bin/rails
In short, I just want to delete all of these RoR-related files, softwares, and every trace of them, and reinstall them clean. Please please help me. I do not want to give up coding. Is it too late to say that I'm sorry?
#This is my .bash_profile
# Enable tab completion
source ~/.profile
# colors!
green="\[\033[0;32m\]"
blue="\[\033[0;34m\]"
purple="\[\033[0;35m\]"
reset="\[\033[0m\]"
# Change command prompt
source ~/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
# '\u' adds the name of the current user to the prompt
# '\$(__git_ps1)' adds git-related stuff
# '\W' adds the name of the current directory
export PS1="$purple\u$green\$(__git_ps1)$blue \W $ $reset"
alias subl="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export RBENV_ROOT=/usr/local/var/rbenv
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
~
"~/.bash_profile" 21L, 720C
Ruby is installed on OS X by default. So you don't want to remove that, there are things that might require ruby that has nothing to do with rails or your rails projects, you should ignore it. (and you should probably not use spotlight for finding dev files, its just confusing as to what is safe and what is not to play with)
Secondly, you'll hardly EVER use sudo for any rails-related work on your mac, so if a tutorial wants you to run that command, don't.
And lastly, its possible it's not as bad as you think. So there's 2 steps. 1 - Fix your rvm environment and 2 - fix your gemfile
TO RESOLVE
--Start be reinstalling RVM
\curl -sSL https://get.rvm.io | bash
Now because it's changed your shell environment (added variables and aliases) and because you've changed some things that are unpredictable... Log out, and log back into your mac.
** Which ruby is in use now? **
which ruby
If you're system is still showing /usr/bin/ruby then you'll need to edit your shell profiles. Because I don't know what you might have done, or what shell env you're using I'll just be thorough. Any excess won't hurt.
You'll review (in the editor of your choice) 4 hidden files in your home directory
/Users/yourhome/.profile
/Users/yourhome/.bashrc
/Users/yourhome/.zshrc
/Users/yourhome/.bash_profile
If you're using bash, then make sure your bash_profile has in it
source ~/.profile
In the bashrc nad zshrc files make sure the rvm path exists
export PATH="$PATH:$HOME/.rvm/bin"
In the .profile file make sure this command exists
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
-- Once you've saved your changes, log out and back in (you shouldn't have have to do this but again, just being thorough).
Once that is done, you should be able to install a ruby -
rvm install ruby-2.2.3
Now if you say rvm use ruby-2.2.3 and then which ruby, you should see a pointer to your home directory where rvm lives.
* Now to fix the Gemfile *
You have an encoding problem, which is what caused you the errors that made you see spots in the first place. If you paste the contents of the file here
(in a terminal in the directory of your rails project)
cat Gemfile
Paste those contents here and it can be fixed.
Can't find anything about this in Google.
Trying to get most out of vim-rails.
https://github.com/tpope/vim-rails
It has many interesting commands, like :Rserver, :Rgenerate, :Rdestroy, but they do not work on my machine. All they give same error:
No such file or directory
I would imagine it has something to do with paths, and RVM loading, but not sure what exactly.
Running on latest Lubuntu if that matters. Sometimes need to do /bin/bash --login to run rake.
--
Found somewhere that in ~/.profile I should put this:
# PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM
Still same error.
--
Yes, vim-rails - is a plugin for vim that I'm trying to use.
-- Tried to run !/bin/bash --login from VIM - but it closes VIm.
Have you try to execute these commands in the normal way?
like rails server, rails generate..
From your description, mostly because vim-rails can't find ruby or rails command to execute.
You should check the $PATH variable to see whether it has ruby or rails load path in it.
Have you tried to open vim in your working directory?
For example, if your app is in ~/workspace/my_project/, then you should open vim in that directory:
cd ~/workspace/my_project
vim
Then the vim-rails should work as expected.
When I want to run rails server it's not working because I need to define every time RVM source in terminal. Like that
~/.rvm/scripts/rvm
If i restart computer then need to define again source then RVM working..
How can I define it permanently in ubuntu 12.10. Please help me
Try to add command source $HOME/.rvm/scripts/rvm into your .bash_profile
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
Similar question was asked here
My system was fine, but today, after installing MySQL server, I can't use the terminal to program my Rails application.
When I open a terminal session, I see:
Last login: Sun Dec 8 13:31:06 on console
-bash: [: missing `]'
-bash: rt: command not found
I tried searching for this error but can't find a solution.
I am running Mac 10.7 OS X.
No commands pertaining to Ruby on Rails are found.
I built an application and installed Rails, but when I run a Rails command I get:
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
How do I fix this?
My bashrc file contains only one line:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
My bash profile contains following:
export PATH=$PATH:/usr/local/mysql/bin
[ [-s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
rt PATH=$PATH:/usr/local/mysql/bin
I checked history and this is what I ran
vi .bash_profile
vi .bash_profile
user#computer:$ mysql -u root
mysql -u root
vi .bash_profile
mysql -u root
/usr/local/mysql-5.6.15-osx10.7-x86_64/bin/mysqld_safe ; exit;
mysql
What else can I show to help with this problem?
Your .bash_profile is messed up. Modify what looks like this:
[ [-s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
rt PATH=$PATH:/usr/local/mysql/bin
To look like this:
[[-s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH=$PATH:/usr/local/mysql/bin
As #TinMan pointed out, you'll want to remove the export PATH line from your .bashrc file.
I had a similar problem (although I'm running Ubuntu). When I opened a new terminal and navigated to my project root, I was surprised to find that Rails was not recognized as a program. I checked the version of Ruby and noted that there was a discrepancy between the two terminals I had open. When I tried to switch Ruby versions with RVM, I was told
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
so I ran /bin/bash --login. Then, I was able to switch to Ruby 2.1.1 with RVM use ruby-2.1.1 and all my rails commands worked again.
Basically what happened is that RVM only installs gems locally for each Ruby verison. Unless you select the version of Ruby that you were using when you installed the gem, you won't be able to use the gem unless you reinstall it.
I came to this page after receiving this error with a slightly different cause. While the CDub's answer is directly applicable to OP's question, I would generally recommend users of Mac OS X Terminal who have this error to do the following:
Open ~/.bash_profile in a text editor.
Look for any instances of "rt" at the beginning of a line.
Change all instances to "export".
It looks like some packages out there are writing a command into ~/.bash_profile that Mac OS X does not like, and we need to manually correct this.
For reference, I am on OS 10.10.2.
I just went about the process of installing ruby and rvm.
This is all very confusing, whilst RVM is working on the terminal I installed it on, it is not working on any other and I am getting the following error:
The program 'rvm' is currently not installed. You can install it by typing:
sudo apt-get install ruby-rvm
Could there be an issue with my paths, or another version of ruby or RVM that is causing this?
Trying sourcing your bash profile.
source ~/.bashrc
Or
source ~/.bash_profile
Also: . ~/.bash_profile works.
This runs your bash profile in your current context (your current shell process) and sets the environment variables so they remain in this context. This is different from executing the .bash_profile like this: ./.bash_profile which will create a new shell, execute the commands there and thus not affect your current shell process.
If you just finished to install it, to have access in all terminals you need to logout and login again, in order to load the new environmental variables on your .bashrc or .bashprofile